Introduction

The WordPress database connection error means PHP reached WordPress code but could not complete a working connection to MySQL or MariaDB. That can come from bad credentials, a crashed database service, resource exhaustion, corruption, or a hosting-side outage. The safest recovery path is to confirm the failure layer before changing anything.

Symptoms

  • WordPress shows "Error establishing a database connection" on the homepage or admin area
  • The site worked recently and then failed without a theme or content change
  • phpMyAdmin, MySQL, or the hosting database panel is unavailable or slow
  • Other apps on the same database server also fail
  • Logs show access denied, too many connections, or database server gone away messages

Common Causes

  • Database name, username, password, or host in wp-config.php is wrong
  • MySQL or MariaDB is down, overloaded, or restarting repeatedly
  • Hosting resource limits or connection limits are exhausted
  • The database server hostname changed during migration or host maintenance
  • Database tables were corrupted after a crash or interrupted write operation

Step-by-Step Fix

  1. Confirm the exact error on the front end and in server logs so you know this is a real database connection failure rather than a generic PHP fatal error.
  2. Check the DB_NAME, DB_USER, DB_PASSWORD, and DB_HOST values in wp-config.php against the credentials shown in your hosting panel.
  3. Test whether the database service itself is reachable through phpMyAdmin, the host dashboard, or a direct MySQL client connection.
  4. If the server is reachable, verify the WordPress database user still exists and still has the expected privileges on the correct database.
  5. Review MySQL and hosting logs for signals like access denied, too many connections, out of memory, or server unavailable so you do not guess at the root cause.
  6. If the database server crashed or is overloaded, stabilize that service first before editing WordPress files or reinstalling plugins.
  7. If logs suggest corruption, back up the current database state and then repair only the affected tables through trusted host tooling or MySQL repair workflows.
  8. Re-test the homepage and /wp-admin/ after each correction so you know whether the fix came from credentials, service recovery, or table repair.
  9. Document the cause, especially if it was migration drift, host limits, or unstable database service, so the same failure does not return on the next deploy or traffic spike.