How to Fix Establishing a Database Connection Error in WordPress

Written by Santosh Prasad

If you are using WordPress website and you have been surfing a web for a while, you have seen this error few times. This error occur due to many reasons.

In this article I will show you how to fix the error establishing a database connection in WordPress.

Please make sure have all full database backup before doing any changes.

Reason Behind Database Connection Error in WordPress

This error occur when your WordPress is unable to establish a database connection. There are lots of reason behind this issue. It could be your database credentials are wrongly configured or may be your database server is unresponsive. May be your database has been corrupted.

Lets troubleshoot this issue.

Are you getting same issue for /wp-admin/ as well?

First of all you have to check that you are getting the same error on the both, front-end of the site and back-end of the site (wp-admin). If you are getting the same error on both pages ” Error establishing a database connection“. If you are getting a different error on the wp-admin panel such as ” One or more database tables
are unavailable. The database may need to be repaired“. Means your database need to be repair.

You can repair your database adding the below line in your wp-config.php file.

define('WP_ALLOW_REPAIR', true);

Once adding the above line access your this page :



During this process user does not need to be logged in to access this functionality when this define is set. This process is only for repair a corrupted database. User also not be able to login when the database is corrupt.

After repaired your database make sure to remove above code from your wp-config.php.

Check wp-config File

wp-config.php file is the most important file in your WordPress site. In this file you specify the details for WordPress to connect to your database. If you have changed your root password or database user password then you will need to edit this file as well with your new password. Always check is if everything is OK in your wp-config.php file.

define('DB_NAME', 'database-name');
define('DB_USER', 'database-username');
define('DB_PASSWORD', 'database-password');
define('DB_HOST', 'localhost');

If your database is running on same server where your app server running. You have mention DB_HOST as localhost. If your database running on different server then replace localhost with the IP. For example:

define('DB_HOST', '');

If everything is looking fine then make sure you check for typos mistake. If still getting the same issue you can say that there is something wrong on the server end.


Thank you! for visiting Look Linux.

If you find this tutorial helpful please share with your friends to keep it alive. For more helpful topic browse my website www.looklinux.com. To become an author at Look Linux Submit Article. Stay connected to Facebook.

About the author


Santosh Prasad

Hi! I'm Santosh and I'm here to post some cool article for you. If you have any query and suggestion please comment in comment section.

Leave a Comment