Error establishing Database Connection

While the "Error Establishing a Database Connection" is a fairly common error, troubleshooting it can take a few different routes. This article will explain the error and go over the different causes and fixes.

What is the "Error Establishing a Database Connection" error?

This error means that your Wordpress script either cannnot locate the database, or is being refused the ability to connect to the database.

What causes this error?

This error can occur due to a few different causes, each one is described along with recommended solution.

Incorrect connection parameters

By far the most common, having incorrect connection credentials will cause the error. These credentials are located in the wp-config.php file found in the root folder for your WordPress installation. There are three credentials: database namedatabase user, and password. Make sure these match the information located in your cPanel. If you know the current database user password, you can reset it.

  1. Log into your cPanel
  2. Under the Databases heading, click the MySQL Databases link
  3. A database does not have a password to reset, but instead we are needing to reset the password for the user assigned to the database.
    At the bottom of the page, under the Current Users heading click on the database user that you would like to reset the password for.  If you don't know the database user assigned to your database, please look for the user in your software's configuration.php file (such as wp-config.php or configuration.php)
  4. On the MySQL Account Maintenance page, enter the old password for the user and then enter the new password you would like. When finished, click the Change Password button.


If you do not know it, you will not be able to view the current password, so you will need to delete and then recreate the database user, giving it the password found in the wp-config.php file. If this is the issue, then the problem should be solved and the site should display normally.

  1. Log into your cPanel dashboard.
  2. Locate the Databases icon from your main cPanel page and click on the MySQL Databases icon.
  3. Once inside the database area, scroll down until you see the MySQL Users Add New Usersection. From here, you will see the form to create your new user. Note that the database name will always be prefixed with your cpanel username. Add the second portion to create the new database username. For example, our new user will be named wp_user100.
  4. Type in the password you desire for both the Password and Password (Again) fields.
  5. Click the Create User button to complete the database user creation.

Corrupted database tables

If you have confirmed the credentials are correct and still get the error, the issue could be caused by corrupted database tables. Database tables can be checked and repaired from within the cPanel. Follow the instructions from our article below to perform the repair.

How to check your tables

  1. Log into your cPanel
  2. Click the phpMyAdmin icon
  3. Choose the database you are working with by clicking on it in the left menu
  4. On the right side of the page, you will see a listing of your tables. Click "Check All" and then from the drop down choose "Check Table"
  5. The page will refresh and give you a summary of table that may be corrupted. As you can see from the screenshot below, all the tables are OK. If you receive any errors, you can continue reading to find how to repair your tables.

How to repair your tables

  1. Log into your cPanel
  2. Click the phpMyAdmin icon
  3. Choose the database you are working with by clicking on it in the left menu
  4. On the right side of the page, you will see a listing of your tables. Click "Check All" and then from the drop down choose "Repair Table"
  5. The page will refresh and give you a summary of the tables that were repaired.
  • 0 Users Found This Useful
Was this answer helpful?

Related Articles

Resetting your password

Resetting your password in WordPress can be accomplished by following these step-by-steps for...

Restoring your database from backup

WordPress database can be restored from backup by following these step-by-step instructions for...

Viewing your WordPress site before DNS resolves

This is a great article that details step-by-step how to view a WordPress site before DNS resolves.

Permalinks do not work - How to fix

Sometimes after a WordPress migration to a different host server is performed, the Permalinks...

WordPress Export Tool

This is a link to a very easy to complete way that you can export your WordPress sites...