Error Establishing a Database Connection in WordPres

How to Fix the Error Establishing a Database Connection

Error Connecting to Database

This maybe one of the simplest error messages wordpress provides. The error message is clear that your website is unable to connect to the database. However solving this error can difficult if you are not familiar with your hosting server.

This error usually occurs when database details have been changed either database hostname, database username, and database password. Sometimes your database server is unresponsive, overloaded, or your database may have corrupted. You would be surprised with the amount of website owners that forget to pay for their hosting.

Most likely an incorrect database or overloaded mysql server.

Repairing your wordpress database.

You should check if the error is on both the front end(viewing website) of the site, and the back-end of the site (wp-admin/login panel). If the error is the same on both pages “Error establishing a database connection”, then proceed onto the next step.

If you are getting an error on the wp-admin for example “One or more database tables are unavailable”

The database needs to be repaired.

You can do this by adding the following line in your wp-config.php file, located at the root level of your wordpress install:


By changing false to true in your wp-config.php file . You will be able to repair your database by navigating to the following URL

Repair a corrupted wordpress database

Remember, the user does not need to be logged in to access the repair database, when this define is set to true. This is because the main reason is to repair a corrupted database.

Users usually cannot login when the database is corrupt.

Once you are done repairing and optimizing your database, remove this code from your wp-config.php.