---
title: "Error establishing a database connection: causes and how…"
description: "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…"
canonical: "https://lemwatch.com/errors/error-establishing-a-database-connection"
source: "https://lemwatch.com"
---

# 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

- 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.
- 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.
- 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.
- 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

- Error establishing a database connection on Cloudflare — Cloudflare caches the error page itself, so visitors keep seeing the database error for minutes after the database is back.
- Error establishing a database connection on WordPress — On shared hosting the database user's connection quota is enforced per account, so a traffic spike or a second site on the same credentials…

## How to stop it happening again

- Monitor for the error string in the response body, not only for the HTTP status — WordPress often returns 500 or even 200 with this message.
- Alert on intermittent failures at peak traffic, which is the early signal of connection exhaustion.
- Add object caching before traffic grows, not after the first outage.

## 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.


## Related

- [All website error codes](https://lemwatch.com/errors)
- [White screen of death](https://lemwatch.com/errors/white-screen-of-death)
- [ERR_CONNECTION_TIMED_OUT](https://lemwatch.com/errors/err-connection-timed-out)
- [ERR_EMPTY_RESPONSE](https://lemwatch.com/errors/err-empty-response)
- [HTTP 500](https://lemwatch.com/http-status-codes/500)
- [HTTP 503](https://lemwatch.com/http-status-codes/503)
- [Free Uptime & response check](https://lemwatch.com/tools/website-uptime)
- [Error establishing a database connection on Cloudflare](https://lemwatch.com/errors/error-establishing-a-database-connection/in-cloudflare)
