Error establishing a database connection: WordPress cannot reach its database

WordPress loaded but could not connect to MySQL. Either the credentials in wp-config.php are wrong, the database server is down, or connections are exhausted under load.

Short answer

WordPress loaded but could not connect to MySQL. Either the credentials in wp-config.php are wrong, the database server is down, or connections are exhausted under load.

What Error establishing a database connection means

This is WordPress's own message, printed before any theme loads. PHP is running fine — the failure is strictly between the application and the database.

Causes and fixes, most likely first

  1. The database server is down or out of memory. Check the database service status and its error log. An out-of-memory kill on a small VPS is the classic cause of an intermittent version of this error.
  2. Credentials in wp-config.php are wrong after a migration or a host password rotation. Verify DB_NAME, DB_USER, DB_PASSWORD and DB_HOST against the host's current values. DB_HOST is not always localhost on managed hosting.
  3. The connection limit is exhausted under traffic. Raise max_connections or add persistent object caching so fewer requests hit the database. Intermittent failures at peak point straight here.
  4. Database tables are corrupted. Enable WP_ALLOW_REPAIR in wp-config.php, run the repair page, then remove the flag immediately — it is unauthenticated while enabled.

Error establishing a database connection on specific platforms

How to stop it happening again

Check your own domain

An external probe records whether the failure is constant or intermittent, and captures the exact minutes it occurs — which is what distinguishes wrong credentials from connection exhaustion.

Frequently asked questions

Why is the error intermittent?

Because the database is hitting its connection limit or being restarted by the out-of-memory killer under load. Constant failure means credentials or a stopped service; intermittent failure means capacity.

How do I fix it after moving hosts?

Update DB_HOST, DB_USER, DB_PASSWORD and DB_NAME in wp-config.php to the new host's values. DB_HOST is the field most often left as localhost when it should not be.

Does this error hurt SEO?

Yes, if it persists. Crawlers treat repeated failures as an unreliable site and reduce crawl rate. A short incident is harmless; a recurring one is not.