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.

Edit Your wp-config file

The wp-config file can be found at the base of your website we teach how to Edit Your wp-config file

Where to locate the wp-config file with wordpress

Tell WordPress to remember your FTP credentials. This simple tells WordPress to remember your FTP credentials so you won’t be asked again when an upgrade is available.

define('FTP_HOST', 'ftp-address'); or website ip address
define('FTP_USER', 'Your_FTP_Username');
define('FTP_PASS', 'Your_FTP_password');

Increase WordPress memory limit

By default, WordPress is configured to limit the php memory it uses to 32M. If you receive a message such as “Allowed memory size of XXX bytes exhausted”, you might want to increase this limit, as shown below:

define('WP_MEMORY_LIMIT', '126M');