Easy fix to error establishing database connection on WordPress

by | Apr 10, 2020 | How To's | 0 comments

No matter you’re a straight-up beginner or an experienced WordPress developer, one time or the other you are guaranteed to experience this error.

No doubt, it’s quite annoying to see this error pop up on the screen. That plain black text on a white background “Error establishing a database connection.“. Ok, enough of the chit-chat, let’s jump straight in.

What is Error establishing a database connection error?

The “error establishing a database connection” error simply means that your WordPress website/installation is having trouble connecting to your MySQL database (Database used by WordPress). Your website requires connecting to the MySQL database to retrieve important information that’s stored in the database tables that pretty much makes up a complete website.

In simpler terms, it’s like HTML and CSS working together to complete the beautiful looking website. πŸ˜ƒ

Why does this error occur?

Now that you’re aware of what this error means, there 3 main reasons as to why you may experience this error which we’ll discuss below.

1. Invalid database credentials

When you first installed WordPress, you may have noticed that you’re required to enter the database username name and password. During this process, WordPress will store your Database’s username and the database user’s password under the wp-config.php (WordPress configuration) file.

The first, possibility is that there might’ve been change to these credentials, in turn, halting WordPress from accessing your Database.

2. Corrupt Database

The second possibility is that your WordPress database could be corrupted. This could be caused by poorly maintained plugins/themes which could be faulty and incompatible with your website.

3. MySQL Crash/Temporarily Unavailable

The third possibility is that your MySQL database isn’t reachable. The server that hosts the MySQL database could have crashed or temporarily be down rendering this error.

Now that you have a possible idea for the reasons causing this error, let’s look into how we can try fixing this error once and for all!

How to Fix Error establishing a database connection?

Let’s go through a step-by-step process to try and fix this error.

1. Check database credentials

The fastest way to check the database credentials is by simply resetting it.

  1. Log into to your File Manager
  2. Locate the wp-config.php file that’s under public_html folder
  3. Open the file in view mode

Once you open the file, you would see something like this:

4. Copy the password without the quotes (‘) in this case ABCDEFG123# and note down the username (in this case hailhost)
5. If you’re using cPanel(For this example, we’ll assume you are), go to the dashboard and click on MySQL Databases under Databases
6. Scroll to the bottom and you will see Current Users
7. Next to your user, click on the Change Password
8. Paste the password that you previously copied as per step 4 and click Change Password

Check your website to verify if the error has been resolved.

If you’re still seeing the error, that means the credentials aren’t the issue. Let’s move into the next step to check your database and repair it.

2. Repair the database

As mentioned before, a corrupted database may also cause this issue. This can be done by using the phpMyAdmin tool that is readily available on the cPanel dashboard.

Note: If you’re having trouble accessing phpMyAdmin, skip this step and proceed to step 3.

1. Click on phpMyAdmin and you’ll be redirected to the phpMyAdmin dashboard where you’ll see your database.
2. On the left side, you will see a list of databases (if you have more than one)
3. Click on the database that is related to your website (This is the value on the wp-config.php file under ‘DB_NAME’)
4. Click on Structure
5. You should now see a list of tables that populate on that page
6. Scroll to the bottom and click Check all which will select all of the tables in that database
7. From the drop-down menu on the right, click repair table

You should now receive a message ‘Your SQL query has been executed successfully.‘ If you receive any errors, note down these errors and go to the next step.

If you see the above success message without errors, check to see if the “Error establishing a database connection.” has disappeared and the website is loading.

3. MySQL Crash/Temporarily Unavailable

If the above steps didn’t work and or weren’t able to access your database and the problem persists, the next logical step would be to contact your web hosting support. It is possible this could be a temporary issue caused on the server’s end. Remember to provide the support with all the steps you’ve taken and any errors you noted down during your troubleshooting.


The Error Establishing a Database Connection error a very common error that you’d encounter with your WordPress website. We’ve covered possible solutions in fixing this error and hope that it worked out for you.

Were you able to identify and fix the Error Establishing a Database Connection error on your WordPress website? Let us know what was causing the issue. We’d love to hear about your experience in the comment section below.

Consider switching to HailHost, Managed WordPress hosting where you won’t be needing to troubleshoot these errors. πŸ˜‰

Any questions? Drop it below and let’s have a discussion!

Have a nice day! 😎