Troubleshooting

"Error Establishing a Database Connection" — How to Fix It

WordPress can't reach its database. Here's how to find out why and restore the connection.

Quick Answer: This error means WordPress can't connect to its MySQL database — usually because the credentials in wp-config.php are wrong, the database server is down, or a table has become corrupted. Check DB_NAME, DB_USER, DB_PASSWORD, and DB_HOST in wp-config.php against your hosting control panel first; if those are correct, confirm the database server itself is running, then check for a corrupted table as the next likely cause.

Site Down With a Database Error Right Now?

Tell us what's happening and we'll help you get it back up — or take it off your plate entirely going forward.

Why This Error Is Different From a Fatal PHP Error

Most WordPress errors — critical errors, white screens, 500s — come from PHP code failing to execute. A database connection error is different: it happens before WordPress can even load its own code, because the very first thing WordPress does on every page load is connect to MySQL to pull the site's content, settings, and configuration. If that connection fails, nothing else can happen, which is why this error appears instead of any normal page.

Step 1: Verify the Database Credentials in wp-config.php

Via FTP or your host's file manager, open wp-config.php in the site's root directory and locate these four lines near the top:

define( 'DB_NAME', '...' );
define( 'DB_USER', '...' );
define( 'DB_PASSWORD', '...' );
define( 'DB_HOST', '...' );

Compare each value against your hosting control panel's database section. This is the single most common cause of the error — a database password that was reset without updating wp-config.php, a site migrated to new hosting with old credentials still in place, or a simple typo. Correcting a mismatched value here resolves the majority of cases immediately.

Step 2: Confirm the Database Server Is Actually Running

If the credentials are correct, the next possibility is that the database server itself is down, overloaded, or unreachable — something to confirm with your host's status page or support, since this is a server-side issue outside of WordPress's files entirely. This is more common on shared hosting during high-traffic periods, where a database server serving many accounts at once can become temporarily unavailable.

Step 3: Check for a Corrupted Database Table

If credentials are correct and the database server is confirmed running, a corrupted table is the next likely cause. Most hosting control panels include phpMyAdmin, which has a built-in "Repair Table" option under the database's structure view. Alternatively, you can temporarily enable WordPress's own repair tool by adding this line to wp-config.php:

define( 'WP_ALLOW_REPAIR', true );

Then visit yoursite.com/wp-admin/maint/repair.php to run the repair. Remove this line from wp-config.php again once you're done — leaving it in place is a security risk, since the repair page has no login requirement while it's enabled.

Step 4: Rule Out a Connection Limit Issue

If the error appears only intermittently or only for some visitors, the hosting account may be hitting a maximum concurrent database connection limit during traffic spikes rather than facing an actual outage or misconfiguration. This is a capacity problem, not a configuration bug, and typically means the hosting plan or database resources need to scale to match the site's actual traffic.

Related Troubleshooting Guides

Martin Van Den Boogerd
Martin Van Den Boogerd
Founder & Owner, CriticalWP — background in cybersecurity and municipal government infrastructure
More about Martin →

Common Questions

WordPress can't reach the MySQL database — usually because the credentials in wp-config.php are wrong, the database server is down or unreachable, or a database table has become corrupted. It can also happen when a hosting account hits its database connection limit during a traffic spike.
Open wp-config.php via FTP and check DB_NAME, DB_USER, DB_PASSWORD, and DB_HOST against the actual values in your hosting control panel's database section. A recently changed database password, a migrated site with old credentials, or a typo in any of these four values will produce this exact error.
Not usually — most cases are a credentials mismatch, a down database server, or a corrupted table, not a compromise. But if it appears alongside other unexplained changes (new admin users, unfamiliar files, altered content), it's worth ruling out unauthorized access as part of the investigation.
Yes. If credentials check out and the database server is reachable, a corrupted table can also trigger this message. Most hosting control panels include a phpMyAdmin "Repair" option, or WordPress's built-in repair tool can be enabled temporarily by adding define( 'WP_ALLOW_REPAIR', true ); to wp-config.php.
If the database server has a connection limit and the site is getting more concurrent traffic than the hosting plan supports, some requests get through while others fail with a database connection error. This is a capacity issue rather than a broken configuration, and usually means the hosting plan or database resources need to scale up.

Database issues shouldn't be a mystery.

Managed WordPress hosting means continuous monitoring catches connection and capacity issues before they become an outage.