Error Establishing a Database Connection

This error message is clear that your website is unable to connect to the database.

Fixing it

1) If you’re moving your WordPress, you should probably check your database login credentials. (Most probably they are wrong or might have been changed.) Meaning to say, the database is right there at your server, just that your connection is not established due to wrong database password or(and) database user.

Go to wp-config.php and edit

Find the line define(‘DB_NAME’, ‘db_name’); and edit it with the name of the database you created earlier. The db_name part of this line will be the new name of your database. Replace this with the name of the database you created earlier.

Next find the line define(‘DB_USER’, ‘db_user’); and edit it. Change the db_user part of this line to the username you created.

Finally, find the line define(‘DB_PASSWORD’, ‘db_password’); and edit it. Replace db_password with the password you created.

2) If you’re getting the error on the front-end of the site, and a different error on the wp-admin like “One or more database tables are unavailable. The database may need to be repaired”, then you need to repair your database.

You can do this by adding the following line in your wp-config.php file:

define(‘WP_ALLOW_REPAIR’, true);

Once you have done that, you can see the settings by visiting this page:


Note that, the user does not need to be logged in to the wp-admin to access this functionality. This is because its main intent is to repair a corrupted database, usually users can not login when the database is corrupt. So once you are done repairing and optimizing your database, make sure to remove this from your wp-config.php. (remove define(‘WP_ALLOW_REPAIR’, true); when done).