This WordPress error means it couldn't reach its database. The cause is almost always the credentials in wp-config.php, the database being down, corrupted tables, or the database hitting its connection limit. Here is how to fix each.
Quick answer
"Error establishing a database connection" means WordPress cannot reach its database. Check that DB_NAME, DB_USER, DB_PASSWORD and DB_HOST in wp-config.php match the real database, that the MySQL service is running, and repair corrupted tables. A database at its connection limit causes it too.
Cause 1: wrong credentials in wp-config.php
After a migration or password change, the details in wp-config.php stop matching the database. Confirm all four:
define('DB_NAME', 'your_db');
define('DB_USER', 'your_user');
define('DB_PASSWORD', 'your_password');
define('DB_HOST', 'localhost'); // sometimes 127.0.0.1If the login itself is denied, see MySQL access denied (1045).
Cause 2: the database server is down
If MySQL/MariaDB isn't running, every site on it shows this error. Restart it and check why it stopped — see MySQL/MariaDB won't start:
systemctl status mariadb && systemctl restart mariadbCause 3: corrupted database tables
A crash can corrupt tables. WordPress has a built-in repair tool — enable it temporarily in wp-config.php, run it, then remove the line:
define('WP_ALLOW_REPAIR', true);
// then visit /wp-admin/maint/repair.phpIf every site on the server is down, the database server itself is the problem. If just one WordPress site is, it's that site's credentials or tables.
Check wp-config credentials first, confirm the DB server is running, then repair tables if needed. One site = config; all sites = the DB server.
Cause 4: too many database connections
On a busy site, MySQL/MariaDB has a maximum connection limit. Once it's hit, new connections — including yours — are refused and WordPress shows this same error. See MySQL too many connections to raise the limit or find what's exhausting it.
Cause 5: the database server is on a different host
On some setups the database runs on a separate server. If DB_HOST points to an internal IP or hostname that changed — after a migration, a new VPS, or a firewall rule — WordPress can't reach it even though the database itself is healthy. Confirm DB_HOST is reachable from the web server.
How to prevent this error
- Back up wp-config.php and your database before any migration.
- Keep database credentials in a password manager so a rotation doesn't break the site.
- Monitor MySQL/MariaDB uptime.
- Set a sane max_connections for your traffic so one spike doesn't lock everyone out.
Related errors
If the site loads but shows a blank page instead of this error, see the white screen of death guide. Migrating to a new server? See how to migrate a WordPress site so the credentials carry over cleanly.
WordPress is a trademark of the WordPress Foundation. ESAGAMES is an independent hosting provider, not affiliated with or endorsed by the WordPress Foundation.