Getting the “Error Establishing Database Connection” page can be a frustrating experience. In most cases, this means your website files are not able to connect to the MySQL service, or the service is not running. The following article will explain how you can troubleshoot these types of MySQL issues.
- The login credentials in the configuration are not correct,
- the MySQL server is not running, or
- he database is corrupted, and in need of repair.
The following article will outline instructions on checking all three.
Checking the MySQL login credentials
If you have recently made any changes to the configuration, or installed WordPress, you can check the wp-config.php file to ensure the credentials match what MySQL expects. The credentials you would need to accomplish this are the host, the database username, the database users password, and the database name itself.
The easiest way to verify these credentials is to navigate to your hosts MySQL interface, and it should list the database with the attached user, as well as have a place to set the password. If you are not able to view the current password, you would want to set it to what is found within your wp-config.php file, to ensure that the credentials match.
Checking the MySQL server
If you have checked your MySQL credentials, and the problem persists, there may be an issue with your MySQL server. To check the status, you can use telnet to view the status of the service. The simplest way to do so would be running the following command:
telnet yourdomain.com 3306
If MySQL is running, this should return output similar to the following:
If it is not running, the Connection will be refused
telnet: connect to address IP ADDRESS: Connection refused
Repairing your Database
The third most common reason for the “Error Establishing a Database Connection” is a corrupt database, which can be caused by a number of things. Some of the reasons include a server crash, or hardware failure as well as processed being killed while writing to the database. These crashes also depend whether you are using MyISAM or InnoDB, as MyISAM is more susceptible to corruption.
To correct this, you can simply add this line to your wp-config.php file:
define( 'WP_ALLOW_REPAIR', true );
Once you have added this, you can reload your website, and should see this message when visiting /wp-admin/
If editing your files is not something you wish to do, the following guide will show you how to repair your database within phpMyAdmin.
Repairing a database in phpMyAdmin
- Login to phpMyAdmin
- Choose the database you are working with by clicking on it in the left menu
- Underneath the database, select Check All to highlight all the tables above
- Using the menu on the right hand side of the Check All option, select Repair Table
- Upon completion, you will see the Success Message
Congratulations! Now you are familiar with troubleshooting the most common causes of the “Error Establishing Database Connection” message. If you are still receiving the error after attempting these steps, then it would be recommended to contact your host for further assistance.