You open your website and instead of your homepage, there’s a plain white page with one line: “Error establishing a database connection.” Your dashboard shows the same thing, or doesn’t load at all.
It looks alarming, but your content is almost always still there. WordPress keeps your posts, pages and settings in a database, and this error simply means WordPress can’t reach it right now. Either the details it uses to log in are wrong, the database server is down, or the database itself needs a repair.
This guide walks through the fixes in order, from the quickest checks to the rare cases. Take a backup of your files before editing anything, if you can reach your hosting panel.
The Usual Causes at a Glance
| Cause | Common after | Fix |
| Database server down or overloaded | Hosting issues, traffic spikes | Check host status, step 1 |
| Wrong database details in wp-config.php | Moving hosts, changing passwords | Correct the details, step 2 |
| Database user missing or without permission | Migrations, manual setup | Reassign the user, step 3 |
| Corrupted database tables | Crashes, failed updates | Run the repair tool, step 4 |
| Database too big or deleted | Exceeded plan limits, account issues | Restore a backup or contact host, step 5 |
If the error started right after you moved your site to a new host, jump straight to step 2. That’s the most likely cause.
Step 1: Check Whether Your Host Is Having Problems
If you didn’t change anything and the site suddenly broke, the problem may not be yours at all.
- Check your host’s status page or social media for outages. Most hosts, including Hostinger and SiteGround, have one.
- Log in to your hosting panel and open phpMyAdmin (or the Databases section). If phpMyAdmin also can’t connect, the database server itself is down.
- Check other sites on the same hosting account. If they’re all showing the error, it’s a server problem.
If the host is at fault, contact support and wait. There’s nothing to fix on your side. If everything looks normal on the host, move on to step 2.
Step 2: Check the Database Details in wp-config.php
WordPress logs in to its database using four details stored in a file called wp-config.php. If any one is wrong, you get this error.
- In your hosting panel, open File Manager and go to your site’s main folder (usually public_html).
- Download a copy of wp-config.php as a backup, then open it to edit.
- Find these four lines:
define( ‘DB_NAME’, ‘your_database_name’ );
define( ‘DB_USER’, ‘your_database_user’ );
define( ‘DB_PASSWORD’, ‘your_database_password’ );
define( ‘DB_HOST’, ‘localhost’ );
- In another tab, open your hosting panel’s Databases (or MySQL Databases) section and compare:
- DB_NAME must exactly match the database name, including any prefix like u123456_.
- DB_USER must exactly match the database username.
- DB_PASSWORD must be that user’s current password.
- DB_HOST is usually localhost, but some hosts use a different server name. Your hosting panel or help docs will show it.
- Correct anything that doesn’t match, save the file and reload your site.
Watch out for small things: an extra space, a missing quote or semicolon, or a name copied from your old host after a migration. If you recently moved your site, our guide to moving WordPress to a new host covers this too.
Step 3: Reset the Database Password and Check User Access
If the details look right but the error stays, the password may have changed, or the user may have lost access to the database.
- In your hosting panel’s Databases section, find the database user.
- Change the user’s password to a new strong one, and copy it.
- Make sure the user is assigned to the database with All Privileges. In cPanel this is under Add User to Database. On Hostinger’s hPanel, it’s in the database’s management options.
- Paste the new password into DB_PASSWORD in wp-config.php and save.
- Reload your site.
This fixes a lot of cases after migrations, where the database was imported but the user was never connected to it. Store the new password in your password manager.
Step 4: Repair the Database
Sometimes the connection works but some database tables are damaged, for example after a crash or a failed update. A sign of this is when the front end shows the error but /wp-admin shows a message asking you to repair the database, or a few pages load and others don’t.
WordPress has a built-in repair tool:
- Open wp-config.php and add this line just above /* That’s all, stop editing! */:
define( ‘WP_ALLOW_REPAIR’, true );
- Visit https://yourdomain.com/wp-admin/maint/repair.php.
- Click Repair Database (or Repair and Optimize Database).
- When it finishes, remove that line from wp-config.php. The repair page doesn’t need a login, so leaving it on is a security risk.
You can also repair tables in phpMyAdmin: select the database, tick all tables, and choose Repair table from the dropdown.
Step 5: If Nothing Else Works
Check for a traffic spike or resource limit
On cheap shared hosting, a sudden rush of visitors or a bad plugin can use up the database server’s connection limit. The error then comes and goes. Check your hosting panel’s resource usage page. If you’re hitting limits often, it’s time for better hosting. See shared hosting vs VPS and our tips to speed up a slow WordPress site.
Restore a backup
If the database is badly damaged or was deleted, restore the most recent backup. Most hosts keep daily backups you can restore from the panel, and plugins like UpdraftPlus can restore yours. Our guide to backing up and restoring a WordPress site walks through it.
Contact your host’s support
Send them the exact error, when it started and what you’ve already tried. They can see server logs you can’t, and database problems are often fixed quickly on their side.
When It Happened to Me
I’ve seen this error myself. It appeared while I was restoring a backup of a site. Instead of the site coming back, I got that plain white page with “Error establishing a database connection”.
I didn’t fix it alone. A developer stepped in and sorted it out, but the site was down for a few hours before it was working again.
Looking back, it makes sense. A restore brings back the database, but if the database name, user or password on the server doesn’t match what’s in wp-config.php, WordPress can’t connect. That’s exactly what steps 2 and 3 above check. If you’re restoring a backup yourself, check those details first, and don’t hesitate to ask your host or a developer for help if the site stays down.
How to Prevent It Next Time
- Back up automatically, with at least a daily database backup stored off the server, such as in Google Drive.
- Update the database details in wp-config.php whenever you change the database password or move hosts.
- Choose reliable hosting with enough resources for your traffic. See our pick of the best web hosting for small businesses.
- Use a caching plugin to reduce database load during busy periods.
- Set up uptime monitoring with a free tool, so you know about an outage before your visitors do.
If you also see a blank white page instead of this error, that’s a different problem. Our guide to the WordPress white screen of death covers it.
Related guides: WordPress Troubleshooting: How to Fix the Most Common Errors · How to Fix “There Has Been a Critical Error on This Website” in WordPress · How to Fix the “500 Internal Server Error” in WordPress
FAQ
Have I lost my website content?
Almost never. The error means WordPress can’t connect to the database, not that the database is gone. Once the connection is fixed, your posts and pages come back.
What is the most common cause?
Wrong database details in wp-config.php, especially after moving to a new host or changing the database password.
Where do I find my database name and password?
In your hosting panel’s Databases or MySQL Databases section. You can see the database name and user there, and reset the password if you don’t know it.
Why does the error come and go?
Usually because the database server is overloaded, from a traffic spike, a heavy plugin or limited shared hosting. Check your hosting resource usage and talk to your host.
Is it safe to use the WordPress repair tool?
Yes, but remove the WP_ALLOW_REPAIR line from wp-config.php straight afterwards, because the repair page can be opened by anyone while it’s on.
Does this error hurt SEO?
Only if it lasts long. If Google can’t reach your site for days, rankings can drop. Fix it quickly and check Google Search Console afterwards.
Final Word
“Error establishing a database connection” sounds serious, but it usually comes down to one wrong detail or a busy server. Check your host first, then compare the four database details in wp-config.php, reset the password if needed, and repair the database if WordPress asks.
And if you don’t have automatic backups yet, set them up today. They turn this kind of error from a crisis into a five-minute restore.


