The Easy Guide To Fix Error Establishing A Database Connection

Your site is growing, traffic is good and you are getting returns for your hard work. And suddenly, when you try to access your site you are presented with “Error Establishing A Database Connection.” That sucks! Now, you have every reason to panic. Where is your website? Where is all the content? Well, you need not panic. Your site is safe, your content is still there. You just need to resolve the “Error Establishing A Database Connection”. How do you do that? Follow the 5 steps mentioned in this easy guide and you are back to where you wanted to be.

Make your WordPress site’s Load Blazing Fast Just by moving to Nestify. Migrate your WooCommerce Store or WordPress Website NOW.

What does Error Establishing A Database Connection Mean?

WordPress stores all your content in the MySQL database of your site. “WordPress Error Establishing a Database Connection” means that WordPress is unable to access the MySQL database. Thus, it cannot present to you the content you have asked. It simply returns you the warning in plain words.

This error can occur for a variety of reasons. Below are the most common ones:

  • A Problem at Host End: Many times, the problem will not be at your end. There might be an issue with your host such as there may be a traffic spike your host is not able to handle. Or simply, the database server is down for whatever reason.
  • Database Is Corrupted: There are so many additions to your database each time you add a plugin, content or change themes. It may happen that your database gets corrupted. At such occasions, you will face this error.
  • WordPress Files Are Corrupted: Sometimes your core WordPress files may get corrupted for whatever reason. It can be as simple as a failed update or as complex as a hacker who chose to corrupt your WordPress files. In any case, corrupted WordPress files can cause this error.
  • Database Login Credentials Are Incorrect: WordPress uses separate login credentials to connect to the MySQL database. If these credentials are incorrect, then you will definitely face the error establishing a database connection error.

Whatever may be the reason, you will quickly get to the solution if you follow this easy guide. We have arranged the steps in such a way so that you will get the quickest and the easiest fix for this error. So, read on.

How to Fix Error Establishing A Database Connection

A) Backup

Before proceeding, we strongly recommend you to take a backup of your site. If something goes wrong, you can fall back to something working. Now, since you are experiencing this error, you will not be able to access your backup plugins. So, just ask your web host to provide you with a backup of database and files. If you are with a good hosting provider, they may even restore the latest backup for you. This can solve the problem in most of the cases. And if it doesn’t you can proceed with the following steps.

B) Contact Hosting Provider

If the backup isn’t resolving the error, you need to reach out to the hosting provider. Now almost all hosting providers are available on live chat. So this can be way faster than trying to resolve the error on your own. You can ask them if there is a problem with the webserver. You can mention that you are getting the error, and they will look into it. They will tell you if there is a problem with traffic, database server, or the database itself. You might get the problem resolved at this stage itself. If it doesn’t, read on.

C) Activate Database Repair Mode

WordPress has a built-in database repair mode that can repair your database. To activate this follow these steps:

Step 1: Connect to your site with an FTP/SFTP client. You can choose from the 5 Best Free FTP Clients for Windows and Mac.

Step2: Download the wp-config.php file which is located under the WordPress folder.

Step 3: You need to edit this file using any code editor or even a simple notepad will do.

Add the following line at the end (just before “That’s all, stop editing”):

Step 4: Upload the file back to the site using FTP. This will overwrite the old version.

Step 5: Go to the Following URL. Just replace sitename with your site address.

You will see the following screen:

database-repair-screen How to fix Error Establishing a Database Connection

Step 6: Select the “Repair Database” option. The repair process will begin. Once the database repair is finished, check if your site is working again. If the error is gone, great! If not, you need to do one more thing.

Step 7: Remove the line that you just added to the wp-config.php file [
define(‘WP_ALLOW_REPAIR’, true); ] and re-upload the wp-config.php file to your site via FTP.

If these steps do not resolve the error, then read on.

D) Update WordPress Installation:

Sometimes, your WordPress files may get corrupted and cause the error. To resolve this issue:

  • Download a fresh copy of WordPress from to your desktop
  • Unpack and delete the “wp-content” folder
  • Upload all the remaining files to your site using FTP. If prompted, choose to overwrite the previous files

This will clean your corrupted WordPress files. Now, check your site once again. We hope by this time, it’s working again. If not, you need to try one last thing.

E) Update wp-config.php File with Correct Credentials

WordPress uses separate login credentials to connect with the database. If these are incorrect, changed or mismatched, then you will get the “error establishing a database connection” warning.

To update your wp-config.php file with correct credentials, follow these steps:

Step 1: Copy the following four lines from the wp-config.php file

Step 2: Reach out to your host, paste these four lines, and ask them if credentials are right. If there is a problem, they will inform you. If you are using managed WordPress Hosting of Nestify, then the support team will correct the credentials for you. Otherwise, you will need to manually correct the database credentials.

Step 3: If your hosting provider gives you the correct credentials and asks to manually upload it, then you need to edit the wp-config file, replace those four lines with the ones you got from your web host and upload the file to your site via FTP.

This should solve the problem of incorrect database credentials. Check your site once again, you may have been free from this error.

Still Getting the Error? Ask Your Hosting Provider to Resolve It For You

After following all these steps, if you are still getting the “error establishing a database connection” then you need not get disheartened. You have done all you could on your part. Now, it’s your hosting provider’s turn to resolve the matter.

Make your WordPress site’s Load Blazing Fast Just by moving to Nestify. Migrate your WooCommerce Store or WordPress Website NOW.

Reach out to your hosting provider, explain to them the steps you took, and ask them to resolve the issue as fast as you can. The time of resolution changes from host-to-host. With Nestify, issues are resolved quickly with zero downtime on your site. You can always count on Nestify’s knowledgable support to help you out with any troubling error.

Leave a Reply