Fixing the “Error Establishing Database Connection” Error

Encountering a database connection error can be frustrating, because it prevents access to the site–including the WordPress Admin Dashboard! In this article, learn what causes the Error establishing a database connection error, and how to resolve this issue.


About Database Connection Errors

If the website is having an issue locating its database, the following error will display:

Error establishing a database connection

This error happens when the configuration files are referencing the wrong database, or the website isn’t able to connect to the correct database. While this error is not specific to WordPress, and could happen for any website with a database, on WordPress sites the most common cause is a misconfiguration of the wp-config.php file.

If a database connection error occurs, it can be frustrating because neither the website or WordPress Admin Dashboard are accessible. However, this issue can be resolved in a couple of ways as long as you have access to the WP Engine User Portal.


Restore the Website

Option one, if it is viable for the website, restore to the last functioning backup point. WP Engine automatically backs up the website each night, and manual checkpoints can be triggered at any time. Any of these backups can be restored to automatically recover the functioning wp-config.php file.

Learn how to restore a backup in the extended guide.


Edit wp-config.php

Option two: If restoring is not a viable option or it does not fix the issue, the wp-config.php file can be edited using SFTP or SSH Gateway.

The wp-config.php file will be located in the root directory of the website.

With the wp-config.php file open, pay special attention to the database settings near the top.

On WP Engine, the database name will always be wp_environmentname and the database username will always be the environment name.

In the example above, the DB_NAME is wp_notarealdatabase and the DB_USER is notarealuser, which is incorrect as the values do not match the current environment. Updating these settings to the correct database name and username will resolve the issue.

In this example, the values are corrected to wp_yourenvironment and yourenvironment.

Once the correct settings are in place, save and upload the file back to the web server. After saving the file, refresh your browser–the website should now be back online!

If the website does not come back right away, try clearing cache.

If you are unable to resolve the database connection error, please contact WP Engine Support for more help.


NEXT STEP: Learn more about common WordPress errors

Still need help? Contact support!

We offer support 24 hours a day, 7 days a week, 365 days a year. Log in to your account to get expert one-on-one help.

The best in WordPress hosting.

See why more customers prefer WP Engine over the competition.