"Error Establishing a Database Connection" is one of the most frightening WordPress errors because your entire site is unavailable to all visitors. But in most cases, your data is 100% intact — the issue is a configuration or server problem, not data loss.
Most common causes we diagnose:
Systematic, fast, and safe process:
Check DB_NAME, DB_USER, DB_PASSWORD, and DB_HOST in wp-config.php. Test credentials manually: mysql -u DB_USER -p DB_NAME -h DB_HOST
Run: systemctl status mysql. If stopped: systemctl start mysql. Check MySQL error log: tail -50 /var/log/mysql/error.log
If MySQL is running but WordPress still shows the error, run: mysqlcheck --repair --all-databases -u root -p
Our WordPress expert responds in minutes.
Almost certainly not. This error means WordPress cannot connect to the database — not that the database is gone or corrupt. Your data is most likely 100% intact.
Host migrations often change the database hostname, username, and password. The wp-config.php values need to be updated to match the new server's database credentials.
WordPress can't reach MySQL. Either the credentials in wp-config.php are wrong, MySQL isn't running, the host/port is unreachable, or MySQL is rejecting the connection (max connections reached, user locked).
Connect to MySQL directly via SSH or hosting panel: `mysql -u user -p database`. If that works, the credentials and DB are fine — the issue is in WordPress config. If it fails, MySQL itself has a problem.
Yes — most common cause. Verify DB_NAME, DB_USER, DB_PASSWORD, and DB_HOST in wp-config.php match your actual MySQL credentials. We always check via the hosting panel.
Common causes: hosting changed the MySQL host/port (rare), MySQL service restarted with different credentials, your account was suspended, password rotation policy changed your DB password, or MySQL hit the max_connections limit.
Indirectly. If MySQL is repairing tables or doing intensive recovery, new connections may be refused while it works. We check MySQL error log for 'innodb' messages indicating recovery state.
If your error log shows 'Too many connections', yes. Edit my.cnf and increase max_connections (default 151, recommend 300-500 for WordPress sites). We also identify why connections are exhausted.
Yes — poorly-coded plugins that don't close connections cause leaks. Eventually max_connections is reached. We use SHOW PROCESSLIST in MySQL to identify which queries hold connections.
Use WP-CLI: `wp db repair` runs MySQL's REPAIR TABLE on each WordPress table. For severe corruption, we use `mysqlcheck --auto-repair --all-databases` from the command line.
Rare but possible. Some security plugins use IP whitelisting for DB user. If your server's IP changes (some cloud hosts do this), the DB user gets blocked. We re-grant access via MySQL.
Sometimes. 'localhost' uses Unix socket; '127.0.0.1' uses TCP. If the socket path is wrong or socket file is missing, switching to 127.0.0.1 (with port if needed) bypasses the issue.
Not connection errors — but data display errors. UTF-8 vs UTF8MB4 mismatches cause weird character display, not connection failures. We migrate to UTF8MB4 for full Unicode support.
Brief outages (under 2 hours): no real SEO impact. Sustained (24+ hours): Google reduces crawl rate. 5+ days down: you risk losing indexed pages. We treat this error as urgent.
Five layers: 1) monitor MySQL connections (alert at 80% capacity), 2) rotate DB passwords carefully (update wp-config first), 3) use connection pooling (ProxySQL), 4) ensure MySQL service auto-restart on failure, 5) maintain regular backups for fast recovery.
Site showing a critical error? We diagnose and fix it fast — same day, no data loss.
Response in minutes. No data loss. No diagnosis charge.
wpfix.blimx.com