WordPress Showing “Error Establishing a Database Connection”? Here's What's Actually Wrong.

A plain page with a single line of text and nothing else — no header, no styling, sometimes wp-admin down along with it — means WordPress could not reach MySQL at all. That's a different, earlier failure than a plugin conflict or a page-builder glitch, and it usually traces to one of a short list of causes once you know where to look.

Database cylinder icon with a broken connection line reaching toward a browser window showing a database connection error
A bare "Error establishing a database connection" message means WordPress never reached MySQL.

What is the problem?

“Error establishing a database connection” is WordPress's own message for one specific failure: it could not open a connection to the MySQL or MariaDB database that holds every post, page, product, setting and user account on your site. WordPress generates this itself, in its core database-handling code, the moment a connection attempt fails — it isn't a plugin error, a theme error, or a hosting error page. It just means the very first thing WordPress needs to do on every single request never succeeded.

Quick answer: this almost always comes down to one of four things — wrong database credentials in wp-config.php, the database server itself being unreachable, too many simultaneous connections hitting your hosting plan's limit, or a database that got moved or renamed without wp-config.php being updated to match.

Because the connection fails before WordPress can query for anything, this affects the entire site at once — the public pages, wp-admin, wp-login.php and the REST API all show the same failure. That total-outage feel is what makes it look worse than it usually is: your content is still sitting in the database exactly as it was, untouched. What's broken is the connection to reach it, not the data itself.

Common symptoms

  • A completely plain page with the single line “Error establishing a database connection” and nothing else — no WordPress styling, no header or footer
  • wp-admin and wp-login.php show the identical message, not just the public site
  • It can be constant (every request fails the same way) or intermittent (works, then fails, then works again) — and which of those two you're seeing is the most useful early clue
  • REST API endpoints (/wp-json/) also fail, since they need the database too
  • It appeared right after a migration, a host change, a database password reset, or a restore from backup
  • Your hosting status page shows everything as operational, because the web server itself is fine — it's specifically the path from PHP to the database that's broken

Why does this happen?

Every WordPress request runs through wp-config.php first, which defines four constants — DB_NAME, DB_USER, DB_PASSWORD and DB_HOST — and hands them to WordPress's database class to open a connection before anything else happens. If any one of those four values is wrong, or if the database server named in DB_HOST can't actually be reached right now, that connection attempt fails and WordPress has no content to serve, because it never got as far as asking for any.

This is also why the error can be intermittent rather than constant. A connection-limit problem isn't a fixed wall — most hosting plans cap the number of simultaneous database connections a site can hold open, and that ceiling only gets hit under certain conditions: a traffic spike, a runaway plugin holding connections open too long, or several visitors landing on a heavy page at once. The error clears once the load passes, but the underlying ceiling is still there waiting to be hit again.

Common technical causes

  • Wrong database credentials in wp-config.php — the single most common cause, especially right after a migration, a host change, or a restore where the new database has a different name, username or password than the old one
  • The database user's password was changed in cPanel or phpMyAdmin without updating wp-config.php to match — the two systems don't sync automatically
  • The database server is down or unreachable — a host-side outage, scheduled maintenance, or the account being resource-suspended
  • Too many simultaneous connections, exceeding what your hosting plan allows — often from a traffic spike, a plugin leaking connections, or several heavy cron jobs running at once
  • An incorrect DB_HOST value — some hosts require a specific hostname, socket path or non-default port rather than the generic localhost, especially after moving to a different server
  • A corrupted wp-config.php file itself, from a bad manual edit — a stray quote or missing semicolon can break the constants before the connection is even attempted
  • The database server's disk is full, which can stop MySQL from accepting new connections even though the server process is technically still running
  • A migrated database imported under a different name or user than what wp-config.php still points to, common when a backup is restored into a fresh hosting account

How to diagnose it

  1. Open wp-config.php via FTP or File Manager and note the current DB_NAME, DB_USER, DB_PASSWORD and DB_HOST values.
  2. Compare them against your actual database in your hosting panel's MySQL Databases (or equivalent) page — the database name and username there need to match wp-config.php exactly.
  3. Try connecting directly with the same credentials through phpMyAdmin or a command-line MySQL client. If that connection also fails, the problem is server-side, not something in your WordPress files.
  4. Check whether the failure is constant or intermittent. Constant almost always means credentials or DB_HOST are wrong; intermittent points toward a connection limit or a server-side resource issue instead.
  5. Check your host's status page and current database connection count against your plan's stated limit, if your hosting panel shows one.
  6. If you migrated recently, confirm DB_HOST actually points at the new server, not a leftover value from the old one.

How to fix it, step by step

  1. Correct the credentials in wp-config.php if they don't match your actual database — update DB_NAME, DB_USER, DB_PASSWORD and DB_HOST to the real, current values.
  2. If you reset the database password anywhere — cPanel, phpMyAdmin, your host's dashboard — update wp-config.php to the new password immediately; the mismatch is the entire cause in this case.
  3. If the database server is down, this is on your host to resolve — open a support ticket with them; there's nothing to fix on the WordPress side while their database service itself is unreachable.
  4. If it's a connection-limit issue, identify what's consuming connections (a runaway cron job, a plugin that isn't closing connections, genuine traffic growth) and either fix that directly or ask your host to raise the limit if the traffic is legitimate.
  5. If a migration left mismatched credentials, update wp-config.php to the database name, user and password the new host actually assigned — these are frequently auto-generated and different from the originals.
  6. Restore wp-config.php from backup if a manual edit corrupted the file itself, rather than trying to hand-fix broken syntax under pressure.
  7. Re-test the site once changed, checking both the public pages and wp-admin, since a fix that only addresses the front end isn't actually complete.

When this needs professional help

A wrong password in wp-config.php is a two-minute fix once you know that's the cause. It's worth bringing in a developer when:

  • You've confirmed the credentials are correct and the direct database connection test still fails, meaning it's a server-side issue you can't resolve yourself
  • The error is intermittent and tied to a connection limit, which needs the actual root cause identified rather than repeated support tickets asking your host to "just fix it"
  • You're not comfortable editing wp-config.php over FTP, or unsure which values are actually correct after a migration
  • The database itself may need a table repair, which carries real risk of data loss if done incorrectly

How I can help

A database connection error looks like the whole site has vanished, which is exactly why it's stressful — but in the overwhelming majority of cases the content is completely intact and the fix is narrow: correct credentials, a resolved connection limit, or a host-side issue chased down properly. Over eleven years of freelance WordPress work I've traced this back to its actual cause more times than I can count, and I fix the specific thing that's wrong rather than reaching for a full restore when one wp-config.php value or one connection ceiling is the real story.

RELEVANT WORK

Builds where the database layer had to hold up cleanly

Two projects where migrating or rebuilding a site meant getting the database connection right the first time, not after a live outage.

Freizeitcenter Dietz

A finished design rebuilt as a responsive WordPress site on Divi 5, with hosting and database setup handled cleanly from the first deploy.

  • WordPress
  • Divi 5
  • Responsive build

Canvascroft

A WordPress and WooCommerce subscription store built from a requirements list, with the database and hosting environment scoped before a line of code was written.

  • WordPress
  • Elementor
  • WooCommerce

FAQ

Questions about a database connection error

What people ask before sending over the site.

Is this the same as the WordPress white screen of death?

No, and they point in different directions. A white screen is usually a PHP fatal error inside a plugin or theme with error output turned off — WordPress and PHP both loaded, something in the code crashed silently. A database connection error happens earlier: WordPress couldn't reach MySQL at all, so it never got as far as running plugin or theme code, and it shows an actual (if brief) message rather than nothing.

Will I lose my content if the database can't connect?

In almost every case, no. Your posts, pages, products and settings are still sitting in the database exactly as they were — what's failing is the connection to reach them, not the data itself. Losing content to this specific error is rare and would point to a separate, much less common disk or storage failure underneath it.

Can a caching plugin cause this?

Rarely as the direct cause, but an object-caching setup (Redis or Memcached) that holds persistent database connections open can make a connection-limit problem worse under load. Temporarily disabling object caching is a reasonable diagnostic step if the error is intermittent rather than constant.

Does this mean my site has been hacked?

Usually not. Most cases trace back to wrong credentials in wp-config.php, a host-side database outage, or too many simultaneous connections — not malicious activity. It's worth a closer look if this appeared alongside other signs of compromise, but on its own it isn't evidence of a hack.

Why does wp-admin show the same error as the public site?

Because wp-admin needs the database just as much as the front end does — every screen in the dashboard, including the login form itself, runs a database query before it can render anything. Nothing in WordPress functions without that connection.

I changed my database password and now this appeared — why?

wp-config.php still has the old password stored in it. Changing a database user's password in cPanel or phpMyAdmin doesn't update WordPress automatically — the two are separate systems, and wp-config.php needs to be edited to match whatever the new password actually is.

How do I know if it's my hosting provider's problem or something in my WordPress files?

Try connecting to the database directly with the same credentials from wp-config.php, using phpMyAdmin or a command-line MySQL client. If that connection also fails, the problem is server-side and it's your host's to fix. If it succeeds there but WordPress still can't connect, the mismatch is in wp-config.php or a WordPress-level cause.

Available for new projects

NEXT STEP

Need help fixing this WordPress issue?

Send me your website and I'll help identify the problem — no charge just to take a look. Based in Bangladesh, working with clients worldwide, with a reply within one working day.

  • Reply within one working day
  • Fixed quote before work starts
  • UK, EU and US hours covered