1. Home
  2. Hosting Management
  3. Troubleshooting
  4. Troubleshooting the WordPress “Error Establishing Database Connection”

Troubleshooting the WordPress “Error Establishing Database Connection”

If you’ve recently attempted to reach your WordPress-based website and instead received a message stating “Error Establishing Database Connection“, the cause is most often one of the following:

  • The database has crashed
  • The database login credentials are incorrect in your WordPress configuration file
  • The WordPress database tables have been damaged

We will walk through these issues one at a time to determine if they affect you, and how to fix them.

Step 1 — Try repairing the WordPress Database

Sometimes, due to a failed upgrade, a database crash, or a faulty plugin, your WordPress database can become corrupted. This problem can present itself as a database connection error. The first thing you can do is try repairing your database.

If you are using cPanel as a control panel at the actual web host, you can easily repair your WordPress database through phpMyadmin.

Additionally, WordPress provides a built-in functions to repair the database. It is disabled by default because it has no access controls and could be a security issue. Below, you will see how we will enable the feature, run the repairs, and then disable it to avoid this potential security threat.

Open the wp-config.php file. On any blank line, paste in the following:

define('WP_ALLOW_REPAIR', true);

This defines a variable that WordPress looks for when determining if it should enable the repair feature.

Save and close the file. Switch over to your browser and load the following address, being sure to substitute with your site’s domain.


A database repair page will load. Press the Repair Database button, and you’ll be taken to a results page where you can see the checks and repairs happening in real-time.

Once the process finishes, be sure to open up the wp-config.php file again and remove the line we just pasted in.

Did you notice any repairs being made? Try your site again, and check whether the error is gone.

Step 2 — Check Database Login Credentials

If you’ve just moved your WordPress site between servers or hosting providers, you might need to update your database connection details. These are stored on the server in a PHP file called wp-config.php.

Now use your favorite text editor to open the configuration file. Locate the database connection information:

/** The name of the database for WordPress */
define('DB_NAME', 'database_name');

/** MySQL database username */
define('DB_USER', 'database_username');

/** MySQL database password */
define('DB_PASSWORD', 'database_password');

Check that these three variables are correct based on your records. If they don’t look right, update as appropriate, save and exit.

If the steps above didn’t solve your issue, you might need to restore the database from a backup if you have one available.

If you’re a ChemiCloud customer, you can rest easy! All our WordPress hosting plans come with 30 day daily offsite backups allowing to be quickly restored.

If you enjoyed this tutorial, then you’ll love our support! All ChemiCloud’s hosting plans include 24/7 support from our amazing support team. Check out our WordPress hosting plans and have your website migrated today!

Updated on August 6, 2020

Was this article helpful?

Related Articles

Need help?
We're always here for you. Submit a ticket or Chat with a live person.
Submit Ticket

Leave a Comment

This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.