← All Guides

"Error establishing a database connection" — what that one line means

One line of unstyled text where your website used to be. It is one of the more alarming things WordPress does, and one of the more mundane things to be wrong: your site cannot reach the database that holds its content. Here is how to find out why.

What you're seeing

A white page with a single line of plain text: "Error establishing a database connection". No layout, no logo, no menu — because none of those exist until the database hands them over. Sometimes there is a second line, "One or more database tables are unavailable. The database may need to be repaired.", which is a more specific and slightly better-natured version of the same problem.

The pattern matters more than the wording:

  • Constant. Every request, every browser, /wp-admin included. Points at credentials or a database server that is not running.
  • Intermittent. Works on refresh, fails again a minute later. Points at capacity — connection limits, load, or a neighbour on shared hosting having a busy afternoon.
  • Front end fails, /wp-admin offers to repair. Points at damaged tables rather than a connection problem.

Establishing which of those you have takes thirty seconds and rules out most of the possibilities.

Why it happens

  • The credentials in wp-config.php no longer match. The classic cause after a migration, or after a host resets a database password during maintenance.
  • The database server is down or overloaded. On shared hosting this is often nothing to do with your site at all.
  • Too many connections. A traffic spike, a bot sweep, or a plugin opening connections and not closing them.
  • Corrupted tables. Usually the result of the server losing power or being killed mid-write.
  • A quota was hit. Databases have size limits and hosting accounts have disk limits. Cross either and writes start failing.
  • The database host name changed. DB_HOST is not always localhost, and a move to a new server or platform frequently changes it.
  • The account is suspended. An unpaid invoice or an overdue card. Unglamorous, and more common than anyone likes to admit.

Safe first steps you can try

  1. Decide whether it is constant or intermittent. Reload half a dozen times over a couple of minutes. This one observation splits the list above roughly in half.
  2. Check the boring things. Is the hosting account active and paid? Does the host have a status page or a maintenance notice? Is MySQL shown as running in the control panel?
  3. Open phpMyAdmin from your control panel. If it opens and your tables are listed, the database is alive and the problem is between WordPress and it — which means credentials. If it will not connect either, the problem is the database server and it is the host's to fix.
  4. Compare the credentials. Open wp-config.php and check DB_NAME, DB_USER, DB_PASSWORD and DB_HOST against what the control panel shows. Watch for a trailing space in the password and for DB_HOST still saying localhost after a move.
  5. Reset the database user's password. If you cannot confirm the password, set a new one in the control panel and paste the same value into wp-config.php. Quicker than trying to remember.
  6. Check your usage. Disk usage for the account and size for the database. If either is at its limit, that is your answer and clearing space fixes it.
  7. Repair the tables, carefully. If WordPress offered to repair, add define('WP_ALLOW_REPAIR', true); to wp-config.php, visit /wp-admin/maint/repair.php, run the repair — and then delete that line straight away. While it is there, anyone at all can run that page without logging in.
  8. Take a database backup the moment you can read it. Export from phpMyAdmin and keep the file somewhere off the server. If the tables are shaky, this is the most valuable five minutes available to you.

What not to do

  • Don't leave WP_ALLOW_REPAIR in place. It is deliberately accessible without a login so you can use it when you are locked out. That is exactly why it must come straight back out.
  • Don't reinstall WordPress. The files are almost certainly fine. Reinstalling changes nothing about a database it still cannot reach, and adds variables to a problem that had few.
  • Don't restore a files-only backup. Many backup tools default to files without the database. Restoring one over a working install replaces the good copy of wp-config.php and can leave you further from home.
  • Don't sit there guessing at passwords. Some hosts throttle or block your IP after repeated failed database logins, at which point you cannot test the correct one either. Reset it instead.
  • Don't assume you have been hacked and start deleting. This particular error is usually infrastructure. Find out which of the causes above it is before treating it as a compromise.

When it's beyond DIY

If phpMyAdmin shows tables that are missing or unreadable, if the host says the database is fine and it plainly is not, or if this has been coming and going for days and nobody can tell you why — call. Database problems are the ones where guessing tends to cost you data, and that is worth avoiding.

We answer 24/7 and the diagnosis starts the moment you call. You get a fixed quote before any work starts, and if we can't help, the assessment costs nothing. See what emergency website repair involves, or just pick up the phone.

That's 1300 WEB SOS. Emergency Website Rescue starts from $1,500 + GST.

Common Questions

Is my website data gone?

Usually not. The message says WordPress could not reach the database, not that the database is empty — the two feel identical from the outside and are completely different problems. Even genuinely corrupted tables are normally repairable. You can confirm quickly by opening phpMyAdmin in your hosting control panel and looking at whether the tables are there.

Why does it sometimes work if I refresh?

Intermittent almost always means capacity rather than configuration. Wrong credentials fail every single time, without exception — so if a refresh occasionally works, the credentials are right and the database server is either overloaded, hitting a connection limit, or being restarted underneath you.

Does this mean I have been hacked?

Usually no. The common causes are credentials that changed, a database server under load, and quotas being hit — none of which involve an attacker. It can occasionally be a side effect of one, for example a flood of traffic exhausting the connection limit, but on its own this error points at infrastructure rather than a compromise.

Want this never to happen again? Protection Plans keep the software updated, monitored and backed up — from $249/month + GST.