How to fix WordPress Error establishing a database connection
See an error like this on your WordPress site?

This error isn't too difficult to fix.
Step 1 - Log into cPanel then Open the File Manager.
Step 2 - Find and click on the domain/subdomain's root folder. This will normally be the public_html folder however if you want to be 100% certain (it can be different for addon and subdomains)
click here for a guide on finding your root folder.
Step 3 - Find the
wp-config.php file, right click and select
Code Edit
If you get this popup box, just click
Edit
Step 4 - Take note of the below lines as they appear on your screen
Step 5 - Keep that window open (we'll need 2 windows open for this), open a new cPanel window and find the MySQL Databases option
Step 6 - Take note of the database names. Note that if you have multiple databases that don't match you may need to repeat step 8 onwards through some trial and error till you find the correct/matching database

Check that the database names match in both the wp-config file and the MySQL Databases section

If they don't match, change the database entry in the wp-config file to match what's in the MySQL Database section
Step 7 - Look at the Add User to Database section in MySQL Databases and the DB_USER and DB_PASSWORD entries in the wp-config file


Make sure that they match (the database user and name don't have to be identical but what's in both sections needs to match) and then hit the
Add button
Step 8 - Select
All Privileges and hit the
Make Changes button down the bottom

Once the change completes, press the
Go Back option in the next screen
Step 9 - Look at the Database Password section in MySQL Databases and the DP_PASSWORD section in wp-config

Step 10 - Click the
Change Password option for the correct database user
Step 11 - Set the database password to what is in the wp-config file, it's easiest to copy/paste it (make sure not to include the ' ' so in this case, the DB password is Q.t555Spy! )

That's should be it!
If you find you're still having trouble, choose the Repair Database option from the MySQL Databases menu to repair the database

If you're still having trouble put through a support ticket and our team will have a look at it for you.
Did you find this article useful?