WebsiteTrouble.com Logo

WebsiteTrouble Blog · Website Errors

Error Establishing a Database Connection: Causes and Fixes

WordPress cannot reach its database. Wrong credentials, a down database server, corrupted tables and hosting limits, and the order to fix them in.

Few WordPress errors stop a site colder than "Error Establishing a Database Connection." No pages, no admin login, just that one line of text. The good news is that this error is honest. It tells you exactly what is wrong: WordPress tried to talk to your database and could not. Here is what that means and the order I check the causes in.

A Quick Word on What the Database Is

Your WordPress site is really two things. The files are the engine: the code, the theme, the plugins. The database is the memory: your pages, posts, settings, users and orders all live in it. When you load a page, WordPress asks the database for the content and builds the page on the spot. No database connection means no content, so WordPress shows that error instead of a broken half-page. My WordPress troubleshooting guide covers this files-versus-database split in more depth if you want the full picture.

Cause One: Wrong Credentials in wp-config

WordPress keeps the database username, password, and database name in a file called wp-config.php. If those details do not match what the server expects, the connection fails instantly. This happens after site moves, after a host resets a database password, after a restore from backup, and sometimes after a well-meaning edit to the wrong file.

The fix is unglamorous: open wp-config, compare the four database values against the real ones in your hosting account, correct what is wrong. Five careful minutes, done.

Cause Two: The Database Server Is Down

Sometimes the credentials are perfect and the database itself is not answering. The database server can crash, get restarted, or be taken down for maintenance by your host. In that case the problem is not in your site at all, and the honest fix is to wait or to call the host and ask, in those words, whether the database server is having trouble.

A clue: if your hosting control panel is also sluggish or showing errors, it is probably their end, not yours.

Cause Three: Corrupted Tables

Databases store everything in tables, and a table can get corrupted, often after a server crash or a disk problem. The site then cannot read its own memory properly. WordPress has a built-in repair mode for exactly this, and your host's control panel usually has a repair tool as well. Corruption sounds catastrophic, but a repair pass fixes it more often than you would expect, and your content is usually intact.

Cause Four: You Have Hit a Hosting Limit

Cheap hosting plans limit how many database connections and how much processing your site gets. A traffic spike, a bot hammering your login page, or a runaway plugin can use all of it up, and then real visitors get the database error. This cause comes and goes, the site works, then falls over, then works again, which makes it easy to misdiagnose. It is related to the intermittent failures I describe in the 500 error post, and the real answer is usually reducing the load or moving up a plan, not changing code.

The Fix Order Matters

Check credentials first because it is fast and common. Then confirm the database server is up. Then look at corruption and limits. My hub post on website error messages in plain English shows how this error reads compared to its cousins, and my website error help page covers how I work a down site from first look to fixed.

When your site is showing this error, it is a repair I handle live on a screen share. You see the wp-config check, the database test and the actual moment your pages come back, so you know it was fixed properly instead of hoping it stays fixed.

Rather have it fixed today?

This is the kind of problem I fix live on a screen share, while you watch. A standard fix is $99 for the first hour, same-day emergency help is $299 for the first hour, and every fix carries a 30-day warranty.