How to fix 'Error establishing a Database Connection' for Wordpress
If you see an error like the below on your Wordpress site, it's likely due to a Wordpress CMS or Plugin update. However it could also mean that your database connection details in your wp-config file have come unsynced with the details on the server. This guide will take you through rectifying this issue.
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
Edit (or Code Edit).
If you get this popup box, just click
Edit again.
Step 4 - Take note of the below lines as they appear on your screen.
Step 5 - Keep that window open, open a new cPanel window and find the
MySQL Databases option.
Step 6 - Take note of the database names.
Step 7 - Check that the database
name and
user matches in both the 'wp-config.php' file and the MySQL Databases section. If they don't match, change the entries in the 'wp-config.php' file to match what's in the MySQL Database section
If you see multiple databases in the MySQL Databases section, choose the database with the matching name to perform the following steps on. If no databases have a name that matches the wp-config.php file, you could either try these steps for each database one by one, or contact your website developer.
Step 8 - 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 the database and user entries match in both cases, and then select the
Add button.
Step 9 - Select
All Privileges and hit the
Make Changes button down the bottom of the page. Once the change completes, press the
Go Back option in the next screen.
Step 10 - Look at the
Database Password section in MySQL Databases and the DP_PASSWORD section in the wp-config file.
Step 11 - Click the
Change Password option for the correct database user
Step 12 - Set the database password to what is in the wp-config file. It's easiest to copy/paste the contents.
You can optionally select the Repair Database option from the MySQL Databases menu to perform several checks on the database.
If this does not resolve the issue it's likely there is another part of the website files that is causing additional problems. We would recommend speaking to your web developer, following these
troubleshooting steps, or
restoring the site from a backup.
For more tutorials on website development and Wordpress troubleshooting, view our List of Wordpress Guides.