Error Establishing a Database Connection: What It Means

VenbitThe Venbit TeamJuly 24, 20265 min read

The short answer

'Error establishing a database connection' means WordPress can't talk to the database that holds all your content. The three usual causes are wrong database credentials (common right after a migration or host change), a corrupted database, or your host's database server being down or overloaded. Each has a specific fix, and some you can do yourself in wp-config.php.

Key takeaways

  • The error means WordPress can reach your site but not its database.
  • Wrong credentials in wp-config.php after a migration or host change is the top cause.
  • A corrupted database is fixable with WordPress's built-in repair mode.
  • If the whole database server is down or overloaded, only your host can fix it.
  • Always take a backup before editing configuration or repairing the database.

"Error establishing a database connection" means WordPress loaded far enough to run, but it can't reach the database where all your posts, pages, and settings live. Think of the database as a filing cabinet and WordPress as the person who needs to open it. This error means the key doesn't work, the cabinet is jammed, or the room it's in is locked. The three real causes are wrong login credentials, a corrupted database, or the host's database server being down.

CauseHow commonThe tell
Wrong database credentialsMost commonIt started right after a migration, host change, or password reset
Corrupted databaseCommonError is intermittent, or the admin says 'database may be corrupt'
Database server down or overloadedCommon on shared hostingOther sites on the same host are affected too; it clears on its own later
Exceeded database connection limitOccasionalHappens under traffic spikes, then recovers when traffic drops
What causes the database connection error

Before you change anything, make a backup of your files and database if you possibly can. Editing configuration or running a repair is safe when done right, but a backup means a mistake costs you nothing.

Check your database credentials in wp-config.php

This is the first thing to check, especially if the error appeared right after you moved hosts, cloned the site, or reset a password. WordPress stores its database login details in a file called wp-config.php in your site's root folder, reachable through your host's file manager or FTP. Four values have to match exactly what your host assigned:

  • DB_NAME, the name of the database.
  • DB_USER, the database username.
  • DB_PASSWORD, that user's password.
  • DB_HOST, usually 'localhost' but some hosts use a specific server address.

Log into your hosting control panel, find the database section (often labeled MySQL Databases), and compare each value against what's in wp-config.php. A single wrong character will break the connection. During a migration, DB_HOST is the usual culprit, because it changes between hosts. Correct any mismatch, save the file, and reload your site.

Try WordPress's built-in database repair

If the credentials are correct and the error is intermittent, or you see a message mentioning the database may be corrupt, WordPress has a repair tool built in. Add this line to wp-config.php, just above the line that says "That's all, stop editing": define('WP_ALLOW_REPAIR', true);

Then visit yoursite.com/wp-admin/maint/repair.php in your browser. You'll get a page with a repair button and a repair-and-optimize button. Run it, let it finish, then delete that line from wp-config.php right away. Leaving repair mode enabled is a security risk because anyone can access that page without logging in.

Rule out the host's database server

If your credentials are right and repair didn't help, the problem may not be your site at all. The database runs on a server, and that server can be down, overloaded, or hitting its connection limit. Two quick checks tell you: look at your host's status page for a reported incident, and, if you're technical, use your host's phpMyAdmin to try opening the database directly. If phpMyAdmin also can't connect, the server side is at fault. This is common on budget shared hosting during traffic spikes, and it often clears on its own once load drops.

When the database server is the problem, there's nothing to fix in your own files. Open a support ticket with your host, tell them phpMyAdmin can't connect either, and let them restart or move your database.

Knowing when to hand it off

Editing wp-config.php and running the repair tool are both within reach for a careful owner. But if you've confirmed the credentials, run the repair, and the error persists, or if it keeps coming back every few days, the underlying cause is deeper: a genuinely corrupt table the built-in tool can't fix, a database outgrowing its plan, or a host that keeps overloading. That's repetitive, fiddly work that's easy to make worse. If your site is also how customers reach you, the downtime cost outweighs the savings of doing it yourself. Bring in someone who can work in the database safely.

How we keep this from taking your site down

This error is one of the classic reasons a site goes dark, and it's covered under the broader category of things that break a live site that we walk through on our website problems page. On our maintenance plans, starting at $99 a month, we keep off-site backups so a corrupt database is an afternoon to restore rather than a disaster, we monitor uptime so we catch the error before your customers do, and we handle host tickets and migrations so credentials never get left mismatched. We're a Seattle-area studio and we've been fixing WordPress since 2011, so this is familiar ground.

More website answers

Every question in this series, from Website Problems, Solved.

Symptoms & emergencies19
What happens if...9
Cost & pricing7
Plans & hiring10
Ownership & switching9
Platform-specific7
Seattle & local2
Venbit

The Venbit Team

Web design & SEO, Seattle

Venbit is a Seattle-area web design, SEO, and digital marketing studio. Since 2011 we've designed, built, and ranked small-business websites for clients across the Puget Sound and around the country, so the numbers and advice here come from real projects, not a content mill.

Common questions

Questions, answered straight.

Straight answers about website fixes for your business. If yours isn't here, ask us directly and we'll give it to you straight.

Ask the team

Almost never. The error means WordPress can't connect to the database, not that the database is gone. Your posts, pages, and settings are still sitting in the database in the vast majority of cases. Once the connection is restored, everything comes back exactly as it was. This is also why keeping a recent backup matters, just in case the rare corruption case is real.

Because migrations almost always change the database credentials, especially DB_HOST. When you copy a site to a new server, the old wp-config.php still points at the old host's database settings. Updating DB_NAME, DB_USER, DB_PASSWORD, and DB_HOST to match the new host's values fixes it. This is the single most common trigger for the error.

Yes, when used correctly. It only attempts to repair and optimize your existing database tables. The one important step is deleting the WP_ALLOW_REPAIR line from wp-config.php as soon as you're done, because while it's enabled the repair page is accessible to anyone without a login, which is a security hole. Take a backup first as a precaution.

Try opening your database directly through your host's phpMyAdmin tool. If phpMyAdmin connects fine but your site doesn't, the issue is your site's credentials or a corrupt table. If phpMyAdmin also can't connect, the database server itself is down or overloaded, which is your host's problem to fix, not yours.

Yes. Every hosting plan caps how many simultaneous database connections it allows. A sudden traffic spike, or a poorly built plugin opening too many connections, can hit that ceiling and throw the error until the load drops. If it only happens during busy periods and clears on its own, an overloaded connection limit is the likely cause, and a bigger plan usually solves it.

Free 30-minute strategy call

Let's talk about your project.

Tell us what you need and we'll give you an honest read on the project, the timeline, and what it takes, before you spend a dollar. Based in Seattle, working across the Puget Sound.

4.8 on Google 5.0 on Yelp