“Error establishing a Database Connection” means WordPress can’t connect to the MySQL database where all your site’s content is stored. The database itself is almost certainly fine. Your content isn’t lost. WordPress just can’t reach it right now. The error blocks the entire site, front end and admin area both.
One diagnostic signal worth noting before troubleshooting: if the error appears instantly with no delay, it’s almost certainly a credentials problem. If there’s a long pause before the message appears, the server is actively trying to reach MySQL and failing, which points to a service-level problem on the hosting end.
Step 1: Check the database credentials in wp-config.php #
The wp-config.php file in your site’s root directory contains 4 values WordPress uses to connect to the database: DB_NAME, DB_USER, DB_PASSWORD, and DB_HOST. If any of these is wrong, the connection fails immediately.
Access wp-config.php via your hosting file manager or FTP and verify these values match your actual database credentials. Find the correct values in your hosting control panel under MySQL Databases (in cPanel) or equivalent. Credentials mismatch is by far the most common cause of this error, especially after a site migration or a hosting provider change.
Step 2: Check whether the database server is running #
If the credentials are correct and the error still appears, the MySQL service on your server may be down. This is outside your control as a site owner and requires your hosting provider’s involvement. Contact support and tell them you’re seeing “Error establishing a Database Connection” and that your wp-config.php credentials are confirmed correct. They can check the MySQL service status and restart it if needed.
Step 3: Repair the database if WordPress says it’s corrupted #
If you can reach wp-admin but see “One or more database tables are unavailable. The database may need to be repaired,” the connection is working but some tables are damaged. Add define('WP_ALLOW_REPAIR', true); to wp-config.php, then visit https://yoursite.com/wp-admin/maint/repair.php. WordPress will repair and optimize the tables. Remove the repair line from wp-config.php after the repair completes.
Why Loupely can’t help directly with this error #
Loupely requires an active WordPress page to capture from. When the Database Connection error takes down the entire site, there’s no page for the extension to work with. The steps above are the manual path through this error. Once the site is back up, running a Loupely diagnosis can confirm whether any plugin-level issue contributed to the database problem (for example, a plugin that attempted a database operation that exceeded server limits).
