Error Establishing a Database Connection in WordPress: Causes and Fixes -- WPFixAgent WordPress repair workspace
All WordPress guides

Critical errors

Error Establishing a Database Connection in WordPress: Causes and Fixes

This message has one wording but several distinct causes -- wrong credentials, a crashed database server, or a corrupted table. Diagnosing correctly matters more than trying fixes at random.

Updated August 18, 20267 min read

One message, several different causes

'Error establishing a database connection' means WordPress's PHP code could not reach or authenticate with the MySQL/MariaDB database it's configured to use -- but that single message covers genuinely different underlying problems that need different fixes. The most common causes, roughly in order of frequency: incorrect database credentials in wp-config.php (often after a migration or a host changing database server details), the database server itself being down or unreachable (a hosting-side outage, not a WordPress problem), the database server being overloaded and refusing new connections (common on shared hosting during traffic spikes), or a corrupted database table making queries fail even though the connection itself succeeds.

Check wp-admin specifically before assuming the worst: if wp-admin shows a different, more specific message ('One or more database tables are unavailable') rather than the generic front-end error, that's actually useful information -- it usually points toward table corruption rather than a pure connection failure, which changes what you try next.

What to check, and in what order

Verify the database credentials in wp-config.php (DB_NAME, DB_USER, DB_PASSWORD, DB_HOST) match what your hosting control panel actually shows for that database -- this single check resolves a large share of cases, especially after a site migration or a host-side password reset that wasn't reflected in wp-config.php. If credentials are confirmed correct, the next step is confirming the database server is actually reachable and running at all; most hosts show database server status in their control panel, and this is worth checking before touching any WordPress files, since no WordPress-side fix can resolve a database server that's actually down.

If credentials are correct and the database server is confirmed running, table corruption becomes the more likely explanation -- this can follow an interrupted write, an abrupt server restart, or a disk issue. Most hosts provide a database repair tool (phpMyAdmin's 'Repair Table' function, or a host-level equivalent) that can often resolve this without data loss, though it's worth taking a database export first if the tool allows it.

Why this deserves care, not just a quick fix

Because the same error message can mean anything from a one-line typo in wp-config.php to an actual hosting outage, guessing and retrying random fixes wastes time on a problem that's costing you visitors and, on a store, revenue every minute. Diagnosing which category you're in first -- credentials, server availability, or table corruption -- means the very next action you take is the right one instead of the fourth or fifth guess.

WPFixAgent's health monitoring reports database connectivity and the specific error text as part of a site's ongoing health signals, so when this happens you already have the timestamp, the exact error, and recent site activity in one place rather than starting the investigation from zero. A restore point taken before any repair that touches the database means a table-repair attempt or a configuration fix that doesn't go as expected has a clear way back.

This guide provides general operational information. Complex security, hosting, database, or custom-code failures may require a qualified specialist.

Continue learning

Related WordPress reliability guides

Critical errors

How to Fix a WordPress Critical Error Without Making It Worse

Recover from the WordPress critical error screen with a controlled process that protects evidence, creates a restore point, isolates the cause, and verifies the result.

Read guide

Plugin conflicts

WordPress Plugin Conflict Detection: A Safer Troubleshooting Guide

Find conflicting WordPress plugins systematically using evidence, reversible isolation, and tests that prove the affected workflow works again.

Read guide

Emergency recovery

How to Recover WordPress When wp-admin Will Not Load

Use a recovery path that loads before normal plugins when wp-admin is unavailable, then verify the site before returning it to service.

Read guide

Free 14-day trial · no card required

Give every WordPress site a safer path from incident to verified recovery.

Install the connector, pair with a one-time token, and start monitoring in minutes -- upgrade whenever you're ready.

Start Free Trial