24/7 Australian Sales & SupportCall 13 24 85
View all Products Close Menu Menu
Troubleshooting "error establishing database connection" on a WordPress site
Updated Thursday January 7th 2021 / Category Web Hosting

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:

  1. Log in to cPanel
  2. Click on the File Manager option
  3. Navigate to the public_html folder (or the folder in which your website is stored).
  4. 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.

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.

  • 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:

  1. Login to cPanel
  2. Click on the File Manager option
  3. Navigate to the public_html folder (or the folder in which your website is stored).
  4. Right-click on the wp-config.php file
  5. Click Edit
  6. Add this line of code to the file define('WP_ALLOW_REPAIR', true);
  7. Click Save Changes
  8. Navigate to http://www.mydomainname.com/wp-admin/maint/repair.php in your web browser
  9. Follow the prompts to repair the database

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.

Can’t find the answers you're looking for? Check out these other methods of support!