You try to load your WordPress site and there it is, this blank white screen that simply says “Error Establishing a Database Connection”. It’s such a simple page but infuriating. What does it mean and why does it keep your site from doing anything? Knowing how to fix the error establishing a database connection in WordPress is usually a quick fix but does require a bit of technical know-how.
WordPress uses the database to store a bunch of information including user information, post content, settings, and a lot more. When WordPress can’t connect to the database, you only have half of what you need to run the site and it just won’t work.
The error establishing a database connection in WordPress means that WordPress can’t connect to the database and is usually caused by one of a handful of problems
- A problem accessing the database because of user settings or other settings
- A problem with the database itself
- A problem with the server (computer) where the database lives
How to Fix the Error Establishing a Database Connection in WordPress
Accessing the Files on Your WordPress Host
First, log into the control panel on your hosting. You should see an option for the File Manager. Open that.
Each server is a bit different, but you’ll need to get to the directory where your WordPress installation is installed. Usually, this is in a directory called something like public_html.
Fixing the Database Connection in the Configuration Settings
WordPress needs certain information to connect to the database. It needs
- Database server
- Database name
- Database username
- Database password
For our examples, we’re going to use the following
- Database server – localhost
- Database name – WPDBName
- Database username – dbuser
- Databasepassword – dbpassword
Make sure to change any values in our examples with the real values from your hosting.
To find those values, you need to look in your Control Panel. There is usually a section called something like databases.
The most common cause of the error establishing a connection to the database is when WordPress has the wrong information to connect to the database. We are going to check that first.
- Looking for the wp-config.php file in the File Manager. Right click on it and select edit.
- Open that file
- Scroll down until you find a section that looks like this:
- Now we will need to check the settings. We need to make sure that what we have in the configuration file is the same as what the server has.
Checking Database User Information on C-Panel
The next part has a few steps, so let’s summarize and then give you the details:
Go to the section labeled “Databases” select MySQL Databases.
Scroll down to the Current Databases section and look for the database that was listed in your wp-config file. If it doesn’t then you will need a developer or your host to help figure out what happened to your data. To the right, you will see the user (or users) that have access to the database. Make sure the user from your wp-config file is listed.
Does your user have access to the database? Then we need to make sure the user exists and their password is right.
If not, then we need to create the user.
Looking at Current Database Users in C-Panel
If that’s all good, then keep scrolling down. At the bottom is the Current User section. Look there to see if the user is there. If they are, then try selecting “Change Password” and set the password to what’s in the wp-config file.
Adding a New Database User in C-Panel
If the user doesn’t exist, we need to make them and then give them access to the database. Scroll up to the Add User section. Fill out the username and password with what is in your wp-config file.
Checking Database User Information on Siteground
Troubleshooting Error Establishing a Database Connection in WordPress is very similar in Siteground but there are a few differences. Let’s take a look at some of those difference.
On the left bar in the Site Tools, click Site. That will open a new window. Select MySQL.
On the next screen that opens, you will see the databases at the bottom. What’s nice about the Siteground interface is they more clearly indicate which database goes with which website. Check that the database for your website is there and that it matches the value in your wp-config file. If they don’t, you’ll need to get some assistance from Siteground or a developer to figure out what happened to your data.
Siteground’s support is really good and it’s worth starting there. You may need to restore from a backup.
Checking Database Users on Siteground
Near the top of that page, you’ll see a navigation bar. Select USERS.
This will open a new page with user information. Scroll to the bottom and see if the user from your wp-config is listed.
If your user is listed, select the three dots under action and select Change Password. Then change the password to what is listed in your wp-config file..
If your user isn’t listed select CREATE USER. This is a bit different. Siteground creates the user name and password, so you will need to copy those down.
Press Manage Access. A new form will open up. Usually, you can just press confirm. Select your database in the dropdown and press All Privileges. Go back to your wp-config file and change the DB_USER value to your new user and the DB_PASSWORD value to the new password.
Does Your Site Work Now?
Try your site again. This will usually fix the issues. If it does, you’re all set. If not, we have a bigger problem. You may need some help from here.