Learn how to fix “Error establishing a database connection” message by WordPress.
We know how annoying it is to get the message “Error establishing a database connection” by WordPress. You get it because WordPress is unable to establish a database connection. The reason you get such warning is that your database login credentials are wrong or have been changed, your database server is unresponsive or database is invalid.
For example, we get this message when the installation of a plugin went unsuccessfully. Below you will find some solutions we propose you to try in order to get rid of “Error establishing a database connection” and get back to the normal working mode. Learn how to quickly fix this error with these solutions that are meant to solve the problem.
WordPress Database Repair
Please make sure that the whole system gives you the same error message, wp-admin area as well as the front-end. If the error message is the same on both pages “Error establishing a database connection”, then proceed onto the next step.
1. You can do this by adding the following line in your wp-config.php file:
2. Once you have done that, you can see the settings by visiting this page: http://www.yoursite.com/wp-admin/maint/repair.php
Check the WP-Config file
This file can be found in your main directory, where WordPress was installed. This is the file where you specify the details for WordPress to connect your database (done automatically when you install WordPress using a hosting tool). If you changed your root password, or the database user password, then you will need to change this file as well. So, please check if everything in your wp-config.php file is the same as it was at the initial stage. This solution worked for us ad we easily solved the “Error establishing a database connection” problem.
define('DB_NAME', 'database-name'); define('DB_USER', 'database-username'); define('DB_PASSWORD', 'database-password'); define('DB_HOST', 'localhost');
Make sure to check these details with the ones you have stated in your hosting account.
Contact your hosting provider
You may notice this Error establishing database connection when your site gets overloaded with a lot of traffic coming to your website. The host server cannot handle the load. Your site may get really slow or even giving you these error messages. It means that you may need a dedicated server or a more generous hosting plan with unlimited resources. Call or email your hosting provider and ask their support if your MySQL server looks responsive to them.
Sometimes, there may be malfunctions from the hosting provider side. They may be in the maintenance mode or they may have unexpected problems. Take some minutes and contact them to figure out what they can do in order to solve your problem. Let them know what error do you have and the period of time you experience the “Error establishing a database connection” issue.
In conclusion we can say that there may be one of these causes or some of them combined. Try each variant to see which one works the best for you. From our experience, these solutions were enough to solve this annoying and unpleasant problem. In most cases, we were back into business within some minutes after we have detected the problem. Enjoy your WordPress experience and we wish you never get such problems again.