Troubleshooting "error establishing database connection" on a WordPress site
There are a few reasons that you might receive an “error establishing database connection” message from your WordPress. Here are some of the causes, and how to fix them.
The database connection details in your wp-config.php file are incorrect
The first thing you should do is verify that the database connection information in your website’s wp-config.php file is correct. You can open the wp-config.php file by following these steps:
Navigate to the public_html folder (or the folder in which your website is stored)
Right-click on the wp-config.php file, then click Edit
Once you have the file open, you can view the database’s name and the associated user under cPanel > MySQL Databases. You can use this information to verify that the details inside the wp-config.php file are correct, except for the server address, which should be set to localhost. More information about the wp-config.php file.
Sometimes the extension that allows PHP to connect to your MySQL database is not enabled. You can check if this is the case under cPanel > Select PHP Version. Depending on the PHP version set, you will see any of the following extensions in the list:
mysql
mysqli
mysqlnd
nd_mysqli
nd_pdo_mysql
Normally, enabling mysql or mysqli will resolve the problem. In some rare cases, you may need to enable mysqlnd and nd_mysql.
The MySQL Database for WordPress is corrupt and needs to be repaired
Sometimes there are issues with the data inside your website’s database, which can be fixed using WordPress’s inbuilt database repair tool. To use the tool, follow these steps:
The MySQL Server is down or inaccessible for some reason
If you have tried all of the above and your website is still displaying the connection error, the MySQL Database Server may be down. In which case, you will need to contact our technical support team for assistance.