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.
| Cause | How common | The tell |
|---|---|---|
| Wrong database credentials | Most common | It started right after a migration, host change, or password reset |
| Corrupted database | Common | Error is intermittent, or the admin says 'database may be corrupt' |
| Database server down or overloaded | Common on shared hosting | Other sites on the same host are affected too; it clears on its own later |
| Exceeded database connection limit | Occasional | Happens under traffic spikes, then recovers when traffic drops |
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.
Related services
More website answers
Every question in this series, from Website Problems, Solved.
Symptoms & emergencies19
- Why Is My Website Down? How to Find Out and Fix It
- Why Does My Website Say "Account Suspended"?
- Error Establishing a Database Connection: What It Means (you are here)
- Why Is My Contact Form Not Sending Emails?
- White Screen of Death on WordPress: What to Do Now
- Why Is My Website Showing "Not Secure" in Chrome?
- Squarespace Site Not Showing Up on Google? Here's Why
- Why Did Google Remove My Website From Search Results?
- Why Did My Website Traffic Suddenly Drop? Top Causes
- Why Is My Website Sending Spam Emails? What It Means
- Why Is My Website Slow on Mobile but Fast on Desktop?
- Why Does My Website Look Broken on My Phone?
- Why Do My Website Images Look Blurry or Broken?
- How to Tell If Your Website Has Been Hacked: 9 Signs
- "This Site May Be Hacked": How to Remove Google's Warning
- "Deceptive Site Ahead" Warning: How to Fix It Fast
- How to Make Your Website Load Faster
- Why Isn't My Business Showing Up on Google?
- 10 Signs Your Business Website Needs a Redesign
What happens if...9
- What Happens If You Don't Update WordPress Plugins?
- What Happens If Your SSL Certificate Expires?
- What Happens If Your Domain Name Expires? A Timeline
- What Happens If Your Web Host Goes Out of Business?
- What Happens If You Stop Paying Your Web Developer?
- Can an Old Website Hurt Your Google Ranking?
- Is an Outdated Website a Liability for Your Business?
- Why Are My Business Emails Going to Spam?
- What Happens If You Don't Maintain Your Website?
Cost & pricing7
- How Much Does It Cost to Fix a Hacked WordPress Site?
- Why Is Website Maintenance So Expensive? A Breakdown
- Hourly Rate vs. Monthly Retainer for Website Updates
- How Much Do Freelancers Charge for Website Maintenance?
- How Much Does WordPress Maintenance Cost Per Month?
- How Much Does Squarespace Maintenance Cost?
- How Much Does Website Maintenance Cost?
Plans & hiring10
- Do I Need a Website Maintenance Plan? An Honest Answer
- Maintenance Plan vs. Pay As You Go: Which Actually Wins
- One-Time Website Fix vs. Ongoing Care: Which Do You Need
- Does a Simple Website Need a Maintenance Plan?
- 12 Questions to Ask a Website Maintenance Company
- Freelancer vs. Agency for Website Maintenance
- What to Look For in a Website Maintenance Contract
- Is Your Website Maintenance Plan a Scam? How to Tell
- Website Maintenance Checklist for Non-Technical Owners
- What Does Website Maintenance Include? (And Why It Matters)
Ownership & switching9
- What Is My Website Built With? How to Check in Seconds
- How to Find Out Who Hosts and Manages Your Website
- Your Web Developer Disappeared: What to Do Now
- How to Switch Web Hosting Without Losing Your Email
- How to Fire Your Web Developer (Without Losing Your Site)
- Can You Maintain Your Own Website Without Coding?
- How Often Should You Update Your Website Content?
- How to Back Up a WordPress Site Yourself (Two Ways)
- Do You Really Own Your Website? How to Check Before You Hire
Platform-specific7
- Do Squarespace Sites Need Maintenance? The Honest Answer
- Do Wix Websites Need Maintenance? What Owners Should Know
- Shopify Maintenance: What Store Owners Actually Need
- WordPress Maintenance Checklist for Non-Developers
- WordPress vs. Squarespace: Which Is Easier to Maintain?
- GoDaddy Website Builder vs. WordPress for Small Business
- How to Keep Your WordPress Website Secure
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.