Fix the Error Establishing a Database Connection in WordPress

As far as WordPress problems go, this can definitely be seen as a big one. If you are seeing the ‘Error Establishing a Database Connection’ on your WordPress dashboard, the time has come for you to take some action. Today, we are going to give you a brief lesson on how to fix the Error Establishing a Database Connection in WordPress, so that you can make your website accessible to users as soon as possible. That being said, buckle up and try to memorize the steps that will lead to the solution of your problem.

Beginning with the basics – why does the error occur in the first place?

Before you can learn how to fix the error, it would be good to know how the error occurs in the first place. When the error happens, WordPress is unable to access the information in the database so the only thing it can do is to show you the error. While there are numerous reasons why this happens, we have selected the most common ones.

  • WordPress files which are corrupted – can occur as a result of failed updates.
  • Incorrect login credentials – changed credentials will result in the error.
  • Corrupted database – happens as a result of a hacker’s attack, a plugin messing up the database internally, etc.
  • The server is down – pretty self-explanatory.
  • Too much traffic – probably the best problem to have but still a problem, nonetheless.
An illustration of an error.
With so many potential problems, identifying the issue can be complicated.

At first glance, you might have a problem distinguishing which one of these things has messed up your website. But once you go through the steps we are about to list, you will not only identify the culprit but also find a solution to your problem. As always, it’s our pleasure to help you out.

How to Fix the Error Establishing a Database Connection in WordPress

While it can get a bit tricky trying to fix this error, you shouldn’t let that discourage you. Especially not since we are about to give you four concise solutions that will most likely fix the problem for you. You just have to put your faith in our trained team.

Step #1 – Checking WordPress database credentials

This is the most common reason why you are seeing the error pop up on your screen. Incorrect database credentials can be a consequence of a couple of things but, most often, it happens after you move your WordPress website to a new host. As for your WordPress database credentials, you can find them stored under the wp-config.php file. What you need to do is check whether the database name, username, password, and database host is correct. To do that, just log into your hosting account and click on MySQL databases which you can find under the databases section.

Bear in mind that you can always contact the web hosting company first and foremost. If you have chosen a good hosting company, you will get help troubleshooting the problem, after which your host will point you in the right direction. That’s just one additional reason why it’s important to make a wise decision and choose a good host.

A woman trying to fix the error establishing a database on a computer.
If step #1 doesn’t solve your problem, you have three more steps to turn to.

Step #2 – Checking the database host information

In case you have confirmed that you are using the right database credentials, but you still haven’t contacted your host, now’s the right time to do it. Most WordPress hosting companies will use localhost, however, some companies use separate servers to host databases. So the next step in your journey to fixing the ‘Error Establishing a Database Connection’ in WordPress is contacting your host and checking database host information. Ready for the third step? Well, our WP Full Care team is more than ready to reveal it to you.

Step #3 – Repairing your WordPress database

In case you are getting a different error on the wp-admin, then you are going to need to repair your database. As for the error, you might see ‘One or more database tables are unavailable. The database may need to be repaired ‘ pop up. In order to fix your database, you are going to need to insert the following code in your wp-config.php file.

  • define(‘WP_ALLOW_REPAIR’, true);

Where do you need to add it? Do you see a line that says ‘That’s all, stop editing! Happy blogging’ line somewhere in your wp-config.php file? Well then add it just before it!

Step #4 – Checking whether your database server is down

Have you gone through all the steps and still haven’t managed to fix the error establishing a database connection in WordPress? Then this is the right time to try step 4 – checking whether your database server is down. Believe it or not, this is very easy to happen – there could just be too much traffic on your host’s server. As a consequence, your site will get slow and will show the error to many of your visitors. The solution is quite simple – just pick up your phone (or live chat) and get in touch with your host. They should be able to tell you whether your MySQL server is responsive.

A man talking on the phone.
Contact your host – they might be able to reveal where the problem originated.

Have you successfully fixed the error?

If you have gone through all the steps mentioned above, chances are you were able to successfully fix the error establishing a database connection in WordPress. But in case you weren’t successful in your efforts so far, you can try updating WordPress site URL using phpMyAdmin. You can also try rebooting the webserver. If you ever get tired of the constant struggles that come with the constant care and maintenance of your WordPress website, and all the problems that can pop up in the meantime, just think about how much you are getting in return from that same website. We are sure you are going to completely change your perspective after some careful consideration.