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