"Error establishing a database connection." Your entire WordPress site disappears — both the front end and the admin dashboard — and visitors see nothing but this error. It sounds catastrophic. In most cases, it's fixable in under 15 minutes.
What this error actually means
WordPress stores all your content, settings and user data in a MySQL database. When WordPress can't connect to that database, it can't render any pages — hence the complete site outage. The error means one of four things: the database credentials in wp-config.php are wrong, the MySQL database server has crashed, the database itself is corrupted, or your hosting server has an underlying issue.
Step 1: Check if it's a hosting server issue
Before touching any files, check whether your hosting provider is having an outage. Go to your host's status page (most have one at status.hostname.com or on their Twitter). If their MySQL service is down, the fix is waiting for them to restore it — there's nothing to do on your end. This accounts for a significant proportion of these errors, especially on shared hosting.
WordPress maintenance plans — proactive monitoring, never miss an outage →Step 2: Verify your database credentials
Connect to your server via FTP or your hosting's file manager and open wp-config.php. Check these four values:
- →DB_NAME — the name of your WordPress database
- →DB_USER — the database username
- →DB_PASSWORD — the database user's password
- →DB_HOST — usually "localhost" but can vary (some hosts use an IP or a named host)
Compare these values against your hosting control panel (cPanel → MySQL Databases, or the Databases section of your hosting dashboard). If the credentials don't match — a common cause after a hosting migration or database password reset — update wp-config.php with the correct values.
Step 3: Repair the database
If credentials are correct but the error persists, your database tables may be corrupted. WordPress has a built-in repair tool. Add this line temporarily to wp-config.php:
define('WP_ALLOW_REPAIR', true);Then visit yoursite.com/wp-admin/maint/repair.php in your browser and click "Repair and Optimize Database". Once the repair completes, remove the WP_ALLOW_REPAIR line from wp-config.php immediately — leaving it in place allows anyone to run the repair tool without authentication.
Step 4: Check your MySQL server via phpMyAdmin
If you can access your hosting control panel, open phpMyAdmin and try to connect to your database directly. If phpMyAdmin can't connect, the MySQL server itself is down — contact your host. If phpMyAdmin connects but your WordPress database shows tables marked as "in use" or "crashed," select all tables, choose "Repair table" from the drop-down and run the repair.
Step 5: Restore from backup
If the database can't be repaired, you need a clean backup. Most managed WordPress hosts (Kinsta, WP Engine, Cloudways) take automated daily backups that you can restore with one click from the hosting dashboard. For shared hosting, check your cPanel for a backup tool or contact support. This is why having an active backup system is non-negotiable — without a recent backup, a corrupted database can mean permanent data loss.
ImportantIf you're seeing this error only on the wp-admin dashboard but the front end of your site works, the problem is likely your wp-admin URL specifically (possibly a caching issue or a wp-config.php directive affecting the admin). Try accessing yoursite.com/?p=1 — if that loads, your database is fine and the issue is specific to the admin path.