Fix WordPress "Error Establishing a Database Connection"
Error establishing a database connectionwp-configdatabase is downThis 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.
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.1
If 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 mariadb
Cause 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.php
If 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.
WordPress hosting that just works
Our web hosting runs WordPress on fast NVMe with managed databases and DDoS protection included.
Frequently asked questions
What causes "Error establishing a database connection" in WordPress?
WordPress can't reach its database — usually wrong credentials in wp-config.php, the MySQL/MariaDB server being down, or corrupted tables. Check the credentials and that the database is running.
How do I know if it's the database server or just my site?
If every site on the server shows the error, the database server is down — restart it. If only one WordPress site does, it's that site's wp-config credentials or corrupted tables.
How do I repair a corrupted WordPress database?
Add define('WP_ALLOW_REPAIR', true); to wp-config.php, visit /wp-admin/maint/repair.php, run the repair, then remove the line. Back up the database first.
Can too many visitors cause this error?
Yes — if traffic pushes MySQL/MariaDB past its max_connections limit, new connections (including WordPress's) get refused and every visitor sees "Error establishing a database connection" until load drops or the limit is raised.
I just migrated my site — why does this happen now?
Migrations almost always change the database host, name, user or password. Update all four values in wp-config.php to match the new database, and confirm the new server allows connections from your web server.
Does this error mean I lost my data?
Not usually — it means WordPress can't currently reach the data, which is different from the data being gone. Fix the credentials or restart the database service first; only run repair tools after confirming the server itself is reachable.
Go deeper on this
Guides and explainers that pair with this fix — from our guides and blog.
How to Speed Up a WordPress Site
Caching, images, PHP version and the hosting underneath.
ReadHow to Secure a WordPress Site
Updates, passwords, plugins and backups that actually matter.
ReadHow to Choose a Web Host
What to look for beyond the headline price.
ReadcPanel vs DirectAdmin vs Plesk
Which control panel does what, and what it costs.
ReadRelated articles
Fix "500 Internal Server Error" on Your Website
A 500 error on your site? The usual causes — .htaccess, file permissions, PHP — and how to fix them.
Read fix Web HostingHow to Point a Domain to Your Server (DNS A Record)
How to point a domain at your server with an A record — and why it doesn't work instantly.
Read fix Web HostingFix Email Going to Spam (SPF, DKIM & DMARC Explained)
Mail landing in spam? Set SPF, DKIM and DMARC correctly so your email reaches the inbox.
Read fix