Skip to content
Web Hosting

Fix WordPress "Error Establishing a Database Connection"

Error establishing a database connectionwp-configdatabase is down
8 min read Updated 12 June 2026 ESAGAMES Team

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.

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
One site or all sites?

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 hosting that just works

Our web hosting runs WordPress on fast NVMe with managed databases and DDoS protection included.

See web hosting
FAQ

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.

Further reading

Go deeper on this

Guides and explainers that pair with this fix — from our guides and blog.

Knowledge base

Related articles

Skip the troubleshooting

Managed, protected hosting in Frankfurt — we handle the Linux, the network and the DDoS so you don't have to.

Payments Secure checkout with cards, banking apps and digital wallets.

Choose the payment flow that fits your stack and region without leaving the platform.

Pay by Zen Visa Mastercard Paysafecard PaysafeCash Skrill Trustly Bancontact UnionPay iDeal WebMoney