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 name, database 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.
- Log into your cPanel
- Under the Databases heading, click the MySQL Databases link
- 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) - 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.
- Log into your cPanel dashboard.
- Locate the Databases icon from your main cPanel page and click on the MySQL Databases icon.
- 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.
- Type in the password you desire for both the Password and Password (Again) fields.
- 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
- Log into your cPanel
- Click the phpMyAdmin icon
- Choose the database you are working with by clicking on it in the left menu
- 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"
- 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
- Log into your cPanel
- Click the phpMyAdmin icon
- Choose the database you are working with by clicking on it in the left menu
- 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"
- The page will refresh and give you a summary of the tables that were repaired.