How to Fix the "Error Establishing a Database Connection"
This is one of the most common and alarming errors for WordPress users. It means your website is "UP" (the server is running), but it can't communicate with your database.
What Does This Error Mean?
Simply put, your website's files tried to log in to your MySQL database to get the page content, but the login failed.
How to Fix Database Connection Errors
1. Check Your wp-config.php Credentials
This is the #1 cause. Your wp-config.php file contains the database login credentials. If these are wrong, the connection will fail.
- Connect to your site via FTP and open
wp-config.php. - Check that the database name, the user, and the host are 100% identical to what's in your hosting control panel.
2. Check if Your Database Server is Down
Sometimes, your web server is running fine, but the separate MySQL server has crashed. Try to access your `phpMyAdmin` from your cPanel. If you can't, contact support.
3. Repair a Corrupted Database
Open your wp-config.php file and add this line at the bottom: define('WP_ALLOW_REPAIR', true);. Visit https://yoursite.com/wp-admin/maint/repair.php to run the repair tool. Remove the line when finished.