Web Hosting
··2 minute readTroubleshooting "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 installation. 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:- Log in to cPanel
- Click on the File Manager option
- 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.
The MySQL extensions for PHP are not enabled
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.- mysqlnd
- nd_mysqli
- nd_pdo_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:- Login to cPanel
- Click on the File Manager option
- Navigate to the public_html folder (or the folder in which your website is stored).
- Right-click on the wp-config.php file
- Click Edit
- Add this line of code to the file
define('WP_ALLOW_REPAIR', true);
- Click Save Changes
- Navigate to http://www.mydomainname.com/wp-admin/maint/repair.php in your web browser
- Follow the prompts to repair the database