WordPress Errors

Error Establishing a Database Connection: What It Means and How to Fix It

One line of text where your website used to be. Here is what causes the error establishing a database connection, how to diagnose it quickly, and when it is your host's problem rather than yours.

Get Shielded
19 Jul 2026 5 min read
Error Establishing a Database Connection: What It Means and How to Fix It

Your entire website replaced by a single line of grey text. No design, no navigation, no explanation. An error establishing a database connection is one of the more alarming WordPress failures, because it takes down the front end and the admin at the same time.

It is also one of the more fixable ones, once you know which of five things is causing it.

What the message actually means

WordPress keeps your content in two separate places. The files — themes, plugins, core code — sit on the server. Everything else — posts, pages, settings, users, orders — lives in a MySQL database.

To build a page, WordPress asks the database for the content. This error means that request failed. The files are fine. WordPress is running. It simply cannot reach the data.

That distinction matters, because it rules out a lot of things immediately. Your theme is not the problem. Your plugins are almost certainly not the problem either.

Cause 1: Wrong credentials in wp-config.php

WordPress reads the database name, username, password and host from wp-config.php. If any one of those four is wrong, the connection fails instantly.

This is the most likely cause if the error appeared right after you migrated the site, changed hosts, restored a backup, or reset a database password in your hosting panel.

Open wp-config.php and check these four lines against what your hosting panel shows: DB_NAME, DB_USER, DB_PASSWORD and DB_HOST.

DB_HOST catches people out most often. It is usually localhost, but plenty of hosts use a specific server address instead. Copy it exactly from your control panel rather than assuming.

Cause 2: The database server is down

Sometimes nothing on your side is wrong at all. The MySQL service on the server has crashed, or the host is having an incident.

Two quick signs point this way. First, other sites on the same hosting account are also failing. Second, your credentials have not changed and you made no edits before it broke.

Check your host's status page, then open a support ticket. There is no fix from your end for this one, and time spent editing config files is time wasted.

Cause 3: The database hit a limit

Shared hosting caps how many database connections a site can hold at once. Under a traffic spike, or with a poorly written plugin holding connections open, you can hit that ceiling. The site then throws an error establishing a database connection intermittently — working one minute, broken the next.

Intermittent is the key symptom. A wrong password fails every time. A connection limit fails only under load.

Short term, your host can raise the limit. Longer term, look at what is generating so many queries: an unoptimised plugin, missing caching, or a site that has simply outgrown its plan.

Cause 4: A corrupted database

Tables can corrupt after a crash, an interrupted update, or a disk problem. The connection succeeds, but the tables cannot be read properly.

WordPress has a built-in repair tool. Add this to wp-config.php:

define('WP_ALLOW_REPAIR', true);

Then visit yourdomain.com/wp-admin/maint/repair.php. Run the repair, then remove that line immediately — while it is present, anyone can access the repair page without logging in.

Cause 5: Something malicious

Less common, but worth ruling out. Malware can modify wp-config.php, and a compromised site sometimes damages database tables. An attacker with access can also change the database password.

Treat it as suspicious if credentials changed with no explanation, if wp-config.php was modified recently and you did not touch it, or if the site was already showing other odd behaviour. Our guide to removing malware from WordPress covers what to check next.

Working through it in order

Diagnose rather than guess. This order finds the cause fastest:

  1. Check the admin. If /wp-admin shows a different message about the database needing repair, go straight to the repair tool.
  2. Check other sites on the same hosting account. If they are down too, it is the server.
  3. Verify the four credentials in wp-config.php against your hosting panel.
  4. Test the connection directly by logging into phpMyAdmin with the same username and password. If that fails, the credentials are wrong or the user lost its permissions.
  5. Ask your host if the site is hitting connection limits.

Do not restore a backup first

The instinct when a site goes down is to roll back. Resist it here.

If the cause is a wrong password or a server outage, restoring a backup fixes nothing and costs you every change since the backup was taken.

Find the cause first. Restoring is the right move for a corrupted database, and the wrong move for the other four causes.

Preventing the next one

Most database failures trace back to hosting that is under-resourced, or to nobody noticing a problem building. Practical steps: keep automatic database backups, use caching so fewer requests reach the database, remove plugins that query heavily without reason, and use uptime monitoring so you learn the site is down before a customer tells you.

That last point matters more than people expect. A site can sit broken for hours overnight, and every one of those hours is lost enquiries.

Our managed website plans include uptime monitoring, automatic backups and performance work, so this class of problem gets caught early rather than discovered by your customers.

Site down right now?

If you have checked the credentials and your host says everything is fine, the cause is usually something less obvious — and every hour offline costs you. Our WordPress error fixing service diagnoses the real cause and gets the site back up, without guesswork.

Get in touch with your web address and what changed just before it broke.

Get Shielded

We build, host, secure and monitor business websites — cleaning up hacks and keeping sites online for clients across the UK, USA, Australia and the UAE.

Keep reading

Chat on WhatsApp