Fix the ‘Error establishing a database connection’ error

Definitions

The ‘Error establishing a database connection’ error means your website can’t connect to its database, preventing it from loading properly. Here is a visual example of the ‘Error establishing a database connection’ error:

Before you start

✅ The database error is nearly always due to incorrect database settings in your WordPress settings or a corrupted database from a bad update.

🚨 The quickest fix for the critical database error is to perform a database data restore.

Step by step

Check your database settings

The ‘Error Establishing a Database Connection’ error usually happens because of incorrect database settings in your wp-config.php file. Follow the steps below to check your database settings.

1. Log in to your hosting control panel

2. Click on the File Manager button

3. Double click on the domains folder

4. Find your website folder and double click on it

5. Look for the public_html folder and double click on it

6. Look for the wp-config.php file and right-click on it

7. From the dropdown, select Edit

8. Inside your wp-config.php file, look for the ‘name of the database’ section:

/** The name of the database for WordPress */

9. Right under, you will find the name of your database. In our example, our database is cloudhelpcenter_77

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

Here is an example of what the section looks like inside of our wp-config.php file:

10. Keep your wp-config.php file. Then, open and load a new web browser tab or window.

11. On your new web browser window, go to your hosting control panel main page

12. From the top right, click the down arrow  and choose the domain you want to check the database settings for

13. Click on the MySQL databases button

14. Find your database name (the same one from your wp-config.php file) and click its Manage button

15. Go to the User Access section, find your database user (typically the same as your database name) and click its Manage button

16.  Go to the Password Management section, click the dice ⚁ ⚁ button to generate a secure password

17. Click the Change Password button

18. You’ll see your new database password. Highlight and copy down your username and password credentials on a secure note. After noting them down, click the X at the top right.

19. Return to the web browser window where your wp-config.php file is open and go to the database password section, for example:

/** Database password */
define( 'DB_PASSWORD', '9F-M3.pS5s)8' );

20. Delete the password inside the quotes ‘ ‘ (do not delete the quotes ‘ ‘ themselves), and enter the new password. Also, run the following checks:

✔️ Make sure your database username is correct

✔️ Make sure your database name is correct

✔️ Make sure your database hostname is set to localhost

Once checked and updated, click the Save File button and X to apply changes and close your session.

  • Here is an example of the process:

21. Return to your website and reload it

Restore your database from backups

If you’re still seeing the ‘Error establishing a database connection’ message after checking your database settings, it may be due to database corruption from a bad WordPress update, or plugin incompatibilities.

Restoring from backups is the quickest way to get your website operational again.

In that guide, use the steps to restore your database from a backup.