Error Establishing a Database Connection in WordPress: How to Fix It
Few WordPress errors stop you as cold as “Error establishing a database connection.” Your whole site is replaced by that single line of text. No layout, no dashboard, no content. It means WordPress tried to talk to its database and got no answer.
Site still broken? Skip the troubleshooting and get emergency WordPress support now. A developer responds within 6 hours, flat $67.
Every piece of your site (posts, pages, users, settings, orders) lives in that database. When WordPress can’t reach it, there’s nothing to show, so you get the bare error instead. The upside is that the causes are a short, knowable list, and several of them you can check yourself in a few minutes. This guide walks through what the error means, why it happens, and how to fix it in order.
If you’re seeing a different symptom, a blank page or a scrambled layout, our full guide to fixing a crashed WordPress site covers every type.
What “error establishing a database connection” actually means
WordPress stores everything except your files in a database, usually MySQL or MariaDB. On every page load, it connects to that database, pulls what it needs, and builds the page. The error appears when that connection fails at the very first step: WordPress asked to connect, and the database either didn’t answer or refused.
Because the connection fails before anything else happens, the whole site goes down at once, front end and dashboard alike. That’s why this error feels so total compared with a single broken page.
Why WordPress can’t reach the database
The usual causes, roughly most to least common:
Wrong database login details. WordPress connects using credentials stored in wp-config.php. If the database name, username, password, or host changed, often after a migration or a host change, the connection is refused.
The database server is down or overloaded. On shared hosting, a traffic spike or a heavy query can exhaust the database’s allowed connections, or the database server itself can go down.
A corrupted database. A failed update or an interrupted write can leave a table damaged, so the connection or the query behind it fails.
Host-side problems. Sometimes it’s simply your hosting provider having an outage, and nothing on your side is wrong at all.
Before you change anything: two quick checks
First, check whether your admin area shows the same error or a different one. Visit yoursite.com/wp-admin. If the front end says “error establishing a database connection” but the admin says something like “One or more database tables are unavailable. The database may need to be repaired,” that points specifically at a corrupted database, which changes the fix.
Second, check whether it’s just this site. If you host other sites with the same provider, see whether they’re down too. If they are, the problem is almost certainly host-side, and the fix is to contact your host, not to touch your site.
How to fix the database connection error, step by step
1. Wait a moment and reload. If the cause was a brief traffic spike that maxed out database connections, the error can clear on its own within a few minutes. Not a real fix, but worth ruling out before you dig in.
2. Check your wp-config.php credentials. This is the most common fixable cause. Open wp-config.php through your host’s file manager or FTP and find four values: DB_NAME, DB_USER, DB_PASSWORD, and DB_HOST. They must match exactly what your hosting database uses. After a migration or a host password reset, one of these is often out of date. Your host’s control panel shows the correct values. Editing wp-config is a core-file change, so make a backup copy first.
3. Confirm DB_HOST is right. Most hosts use “localhost,” but plenty don’t. Some use a specific server name or an IP address. If the other three values look correct, a wrong DB_HOST is a common quiet culprit. Your host’s documentation or support will tell you the right value.
4. Repair the database. If your admin hinted the database needs repair, WordPress has a built-in tool. Add a line to wp-config.php that sets WP_ALLOW_REPAIR to true, then visit yoursite.com/wp-admin/maint/repair.php and run the repair. Remove that line afterwards, because leaving it enabled is a security risk.
5. Check whether the database server is responsive. This is where it gets technical. Confirming the database user still has permission, or that the server isn’t refusing connections, usually means logging into your host’s database tools like phpMyAdmin, or asking your host directly. If you’re not comfortable there, this is a sensible handover point.
6. Ask your host. If credentials are correct and a repair didn’t help, the problem is likely on the server: a downed database service, a resource limit, or a provider outage. Your host can see things you can’t, and this is squarely their job.
Is it your site or your host?
A quick way to tell them apart: if the wp-config.php credentials are correct and unchanged, and the error appeared without you touching anything, suspect the host. If the error started right after a migration, a host move, or a password change, suspect the credentials. The first is theirs to fix; the second is usually a one-value correction.
When to stop and get help
The database connection error crosses into expert territory faster than most WordPress problems, because the database is the one place a mistake is hardest to undo. Hand it over when:
- Credentials look correct but the error persists.
- The fix involves editing the database directly through phpMyAdmin.
- A repair didn’t work, or reported errors it couldn’t fix.
- There’s any sign the database was tampered with.
A damaged database is the kind of problem where careful, experienced hands save you far more than the fee. Ongoing WordPress support covers exactly this.
How to prevent database connection errors
- Keep off-site backups that include your database, so a corrupted table is a restore, not a rebuild.
- Choose hosting with database resources that match your traffic, and watch for repeated connection limits.
- After any migration, confirm the wp-config credentials before pointing your domain at the new server.
- Keep an eye on plugins that hammer the database, like poorly built stats or related-posts plugins.
Most of these come down to good hosting and steady maintenance, the same habits that prevent most WordPress emergencies.
Frequently asked questions
What does “error establishing a database connection” mean?
It means WordPress tried to connect to its database and failed, so it can’t load any content. The usual causes are wrong database credentials in wp-config.php, a database server that’s down or overloaded, a corrupted database, or a host-side outage.
How do I fix the database connection error in WordPress?
Check your wp-config.php database name, user, password, and host against what your hosting uses, since a mismatch after a migration or password change is the most common cause. If those are correct, try WordPress’s built-in database repair, and if it still fails, contact your host, because it’s likely server-side.
Why did this error appear without me changing anything?
Then it’s probably not your credentials. A sudden error with no change on your side usually means the database server is overloaded or down, or your host is having an outage. Check whether other sites on the same host are affected, and contact your provider.
Can I fix a database connection error myself?
Sometimes. Checking and correcting the wp-config credentials and running the built-in repair tool are within reach if you’re comfortable editing one file. Anything that means working directly in the database, or diagnosing the server, is usually better handed to your host or a developer.
Will I lose data from a database connection error?
Usually not. The error is about reaching the database, not losing it. But if the cause is a corrupted database, a recent backup is your safety net, which is why frequent off-site backups matter so much.
Get your database error fixed risk-free with a 7-day money-back guarantee →