“Error establishing a database connection” in WordPress: causes and fixes
A specific WordPress error message explained: what causes it, how it differs from a white screen, and the order to troubleshoot it in.
13 November 2026 6 min read
If your WordPress site is showing the message “Error establishing a database connection” instead of your homepage, you’re looking at one specific, well-defined problem: WordPress cannot talk to its MySQL or MariaDB database. This is a different fault to the general White Screen of Death, and it has its own set of likely causes and its own fix order. This guide walks through both.
What this error actually means
Every page load on a WordPress site involves PHP asking the database for content: post text, settings, menu structure, plugin data, all of it. When that request fails outright, WordPress has a dedicated check for it and shows this exact message rather than letting the page fail silently. It’s WordPress telling you, specifically, “I can run, but I can’t reach my data.”
That specificity is useful. It rules out a whole category of problems (broken PHP in a plugin or theme, a fatal error in your code) and points you straight at the database layer: credentials, the database server itself, or the tables within it.
How this differs from a White Screen of Death
The White Screen of Death (WSOD) is a blank page with no error message at all, usually caused by a PHP fatal error somewhere in a plugin, theme, or WordPress core, often linked to memory exhaustion or incompatible code. A database connection error is not blank and not silent. It shows you a plain-English message. If you’re seeing wording on the screen, you’re not dealing with a WSOD, and the fixes below (not the general white screen troubleshooting steps) are the relevant ones.
| Symptom | Database connection error | White Screen of Death |
|---|---|---|
| What you see | A specific text message on screen | A completely blank page |
| Likely layer | Database credentials, server, or tables | PHP code, plugin or theme, memory limit |
| First thing to check | wp-config.php database settings | PHP error log |
Cause 1: incorrect database credentials in wp-config.php
This is the single most common cause, and the good news is it’s the easiest to check. The file wp-config.php, in your WordPress root directory, holds four values WordPress needs to reach the database: DB_NAME, DB_USER, DB_PASSWORD, and DB_HOST. If any of these no longer match reality, perhaps a database password was reset, a migration changed the database name, or a hosting move changed the host value, WordPress will fail to connect and show this error.
Open wp-config.php with a text editor (via FTP, SFTP, or your host’s file manager) and confirm each value against the actual database. You can check the real database name and username in phpMyAdmin or an equivalent database management tool, and confirm the password with whoever last set it, or reset it and update wp-config.php to match. DB_HOST is usually “localhost”, but not always, particularly if the database runs on a separate server to your web files, so don’t assume it’s correct without checking.
Cause 2: the database server is down or unreachable
Sometimes the credentials in wp-config.php are perfectly correct, but the database server itself isn’t responding. This can happen because the MySQL or MariaDB service has crashed or been restarted, the server has hit a connection limit under heavy load, or there’s a network issue between your web server and a separately hosted database.
If you have access to phpMyAdmin or a command line, try connecting to the database directly using the same credentials from wp-config.php. If that connection also fails, the problem sits with the database service itself rather than with WordPress, and you’ll need your hosting provider to check the database server’s status, restart it if needed, or investigate whether a connection limit is being hit. If other sites on the same server are also affected, that’s a strong sign this is a server-wide issue rather than something specific to your install. This kind of shared-resource problem is one reason some site owners move to VPS hosting, where server resources aren’t shared with other customers’ sites.
Cause 3: a corrupted database needing repair
If credentials are correct and the database server is reachable, but the error persists, one or more database tables may have become corrupted. This can follow an abrupt server shutdown, a failed import, or a disk-related fault. WordPress has a built-in repair tool for exactly this situation.
Add this line to wp-config.php, above the line that reads “That’s all, stop editing! Happy publishing.”:
define( 'WP_ALLOW_REPAIR', true );
Then visit yourdomain.co.uk/wp-admin/maint/repair.php in your browser. You’ll be offered two options: “Repair Database” or “Repair and Optimize Database”. Either will scan your tables and attempt to fix corruption it finds. Once you’re done, remove the WP_ALLOW_REPAIR line from wp-config.php again. Leaving this page accessible is a security risk, since anyone who finds the URL can trigger a repair, so don’t skip this step. Before running a repair, if you’re able to, take a database backup first: repair tools are generally safe, but a backup costs you nothing and protects against the unexpected.
Cause 4: corrupted WordPress core files
Less common, but worth ruling out: if the core WordPress files responsible for the database connection itself (wp-includes/wp-db.php in particular) have been corrupted or partially overwritten, perhaps by a failed update or a hosting-level file system fault, you can see this same error even with correct credentials and a healthy database. The fix is to re-upload a clean copy of WordPress core. Download the same version from WordPress.org, and replace the wp-admin and wp-includes folders entirely (do not touch wp-content, where your themes, plugins, and uploads live). This won’t affect your content, since none of your data lives in those core folders.
Step-by-step troubleshooting order
- Check wp-config.php against the actual database name, username, password, and host.
- Try connecting to the database directly through phpMyAdmin using those same credentials, to confirm whether the database server itself is reachable.
- If the server is reachable but the error persists, back up the database, then run the built-in repair tool using WP_ALLOW_REPAIR.
- If repair doesn’t resolve it, re-upload clean copies of the wp-admin and wp-includes folders from a matching WordPress.org release.
- If none of the above resolves it, contact your hosting provider: at this point you’re likely dealing with a server-side database fault that needs their access to diagnose.
Summary
“Error establishing a database connection” is a specific, on-screen message, distinct from the blank-page White Screen of Death, and it points squarely at the database layer. Work through it in order: credentials first, then whether the database server is reachable at all, then table corruption, then core file corruption. Most cases are solved at the first or second step. Keep a recent database backup before running any repair, and always remove WP_ALLOW_REPAIR from wp-config.php once you’re finished with it.