The Easy Guide To Fix Error Establishing A Database Connection

Table of Contents

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 an “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, and your content is still there. You need to resolve the “Error Establishing A Database Connection.” How do you do that? Follow the five steps in this easy guide, and you are back to where you wanted to be.

 

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 cannot access the MySQL database. Thus, it cannot present the content you have asked for. 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 the database server is down for whatever reason.
  • Database Is Corrupted: There are many additions to your database each time you add a plugin, content, or change themes. Your database can get corrupted. On such occasions, you will face this error.
  • WordPress Files Are Corrupted: 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 face the error establishing a database connection error.

 

Whatever 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 easiest fix for this error. So, read on.

 

How to Fix Error Establishing A Database Connection

 

A) Backup

 

Before proceeding, we strongly recommend you take a backup of your site. If something goes wrong, you can fall back on something working. Now, since you are experiencing this error, you will not be able to access your backup plugins. So, ask your web host to provide you with a backup of the 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 cases. And if it doesn’t, you can proceed with the following steps.

 

B) Contact Hosting Provider

 

You need to reach out to the hosting provider if the backup isn’t resolving the error. Now almost all hosting providers are available on live chat. So this can be way faster than trying to fix 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, the database server, or the database itself. You might get the issue 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” ):

define('WP_ALLOW_REPAIR', true);

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 the site name with your site address.

 

sitename.com/wp-admin/maint/repair.php

 

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. Suppose 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 WordPress.org 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, 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.

define('DB_NAME', 'xxxxxxxx');
define('DB_USER', 'xxxxxxxxx');
define('DB_PASSWORD', 'xxxxxxxxxx');
define('DB_HOST', 'xxxxxxxxxx');

 

Step 2: Reach out to your host, paste these four lines, and ask them if the credentials are correct. 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. Otherwise, you will need to fix the database credentials manually.

 

Step 3: If your hosting provider gives you the correct credentials and asks you to upload it manually, 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,” you need not be disheartened. You have done all you could on your part. Now, it’s your hosting provider’s turn to resolve the matter.

 

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

 

Fully Managed WordPress Hosting

Nestify’s AWS powered dedicated CPU servers keep your sites fast, secure, and always up to date.

Want faster WordPress?

WordPress Speed Optimization

Try our AWS powered WordPress hosting for free and see the difference for yourself.

No Credit Card Required.

Whitelabel Web Hosting Portal Demo

Launching WordPress on AWS takes just one minute with Nestify.

Launching WooCommerce on AWS takes just one minute with Nestify.