DB connection critical
Error establishing a database connection (WordPress)
WordPress cannot reach or authenticate to MySQL, so PHP renders a blank page with a single error line instead of your site.
What you see
Error establishing a database connection
What’s actually happening
Your whole site, including wp-admin, shows one line of text on a white page. It can hit every visitor at once, or flicker on and off under traffic when MySQL runs out of connections. Sometimes the front end loads from cache while the admin is dead. The browser returns HTTP 500 with no PHP stack trace because WordPress catches the failure early in wp-db.php.
Common causes
- Wrong DB_NAME, DB_USER, or DB_PASSWORD in wp-config.php after a migration or host password reset
- MySQL/MariaDB service is stopped or crashed (OOM-killed is common on 1GB droplets)
- DB_HOST is wrong — 'localhost' vs '127.0.0.1' vs a remote socket the firewall blocks
- max_connections exhausted under load, so new PHP workers get rejected
- A corrupted table after an unclean shutdown, which mysqlcheck reports as 'crashed'
How to fix it
- Confirm the database is actually runningSSH in and run `systemctl status mariadb` (or mysql). If it's dead, `journalctl -u mariadb --no-pager | tail -50` usually shows an OOM kill or a corrupt InnoDB log. Start it with `systemctl start mariadb` and watch whether it stays up.
- Verify credentials against MySQL directlyPull DB_USER/DB_PASSWORD from wp-config.php and test them: `mysql -u WPUSER -p -h 127.0.0.1 WPDB`. If that login fails, the problem is credentials or the user's host grant, not WordPress. Reset with `ALTER USER 'WPUSER'@'localhost' IDENTIFIED BY '...';` then `FLUSH PRIVILEGES;`.
- Fix DB_HOST mismatchesIf MySQL listens on a Unix socket, 'localhost' works but '127.0.0.1' forces TCP and can fail when bind-address is 127.0.0.1 only. Managed hosts often need a full hostname like `db.example.internal:3306`. Match wp-config.php DB_HOST to what `mysql` actually connects with.
- Repair crashed tablesAdd `define('WP_ALLOW_REPAIR', true);` to wp-config.php and visit /wp-admin/maint/repair.php, or run `mysqlcheck -u root -p --auto-repair --check WPDB`. Remove the define line afterward so the page isn't public.
- Raise connection limits if it's load-drivenIf the error appears only at peak traffic, MySQL is hitting max_connections. Bump it in my.cnf, add a persistent object cache (Redis), and cap PHP-FPM pm.max_children so workers can't outnumber available DB connections.
Stop it recurring
Keep a known-good copy of wp-config.php credentials and put MySQL behind monitoring that alerts on restarts and connection-pool saturation.
Related errors