web analytics

How to Solve Error Establishing Database Connection in WordPress

As we know WordPress is powered by a database at the backend which the WordPress software connects to and pages are dynamically created based on the queries to the database. Therefore, if you see the message Error Establishing Database Connection, it means that WordPress has not been able to access the backend database. which will mean that your website will be practically down and not visible to the world.

It is important that while attempting any of the solutions, you already have reliable backup of your website.?

There are different situations which can cause throwing up of this error messages. One possible cause is that there is some problem with the database and it needs to be repaired. In order to ensure this, you need to see if you can login to your WordPress Dashboard and only other website pages are throwing this error. WordPress software itself is powerful enough to address this situation. Access the WordPress files via FTP and insert the following line in the wp-config.php file. If the parameter is already there, you can set its attribute from false to true and uncomment the?file.

define('WP_ALLOW_REPAIR', true);

As you will do this and visit your wordpress website at http://yourwebsiteurl.com/wp-admin/maint/repair.php , you will get the option to repair database. You click on that and WordPress will try to repair the database. If the problem is not solved, you can try to solve the other options. This repair function can be used even without you having the admin access to your WordPress site.

Secondly, you need to check your wp-config.php file and ensure that the following parameter are exactly as required. If you have changed your database password from cPanel etc, then you need to reflect in this file as well to ensure that your website does not throw error establishing database connection problem.

1 define('DB_NAME', 'dbname');
2 define('DB_USER', 'db-username');
3 define('DB_PASSWORD', 'db-password');
4 define('DB_HOST', 'localhost');

If the above two solutions do not work, then it means that there is not problem with your own website database or WordPress. The problem might be more widespread and there might be problem with the database server at web host level. In that case you need to contact your web host and they will be able to advise you further. One way to check if the problem is with the web host database server is to see if your other websites hosted on the same server are also showing this problem. If it is a problem on all sites then it is sure that something is wrong at the web hosting.

Some people have suggested that they were able to fix the problem by installing WordPress afresh. There are also other solutions to this error establishing database connection in WordPress. Some of these, reported by different users on the web are:

  • removing plugins
  • define('DB_HOST', '127.0.0.1:8889'); (using the IP instead of local host in this field)
  • changing the user in ‘define('DB_USER', 'db-username');' to root user

 

Leave a Reply

Share This