You open your WordPress site, and instead of your homepage, you see a white screen with a blunt message: “Error Establishing a Database Connection.” Your site is down. Visitors cannot reach you. Panic sets in. The good news? This error almost always has a fixable cause. In most cases, you can resolve it in under 15 minutes without touching a single line of complex code.
This guide walks you through exactly 5 steps to diagnose and fix the “Error Establishing a Database Connection” in WordPress, starting with the simplest fixes first and working toward deeper solutions only if needed.

WordPress stores all your content (posts, pages, settings, users) in a MySQL database. Every time someone visits your site, WordPress connects to that database to fetch and display the right content. When that connection fails, WordPress cannot load anything.
Instead, it throws the “Error Establishing a Database Connection” message on the front end. You may also see a slightly different message when trying to access your WordPress admin (wp-admin):
“One or more database tables are unavailable. The database may need to be repaired.”
Both messages point to the same underlying problem: WordPress cannot talk to its database.
Before jumping into fixes, it helps to understand why this happens:
Follow these five simple, progressive steps to troubleshoot and fix the database connection error, get your WordPress site back online safely, and prevent future downtime in minutes.
The most common cause of this error is incorrect database credentials. When you first set up WordPress (or migrate a site), the database name, username, password, and host stored in wp-config.php must exactly match what your hosting provider has on file.
1. Access your website files via FTP (using FileZilla or similar) or through your hosting control panel’s File Manager.
2. Navigate to your WordPress root directory and open wp-config.php.
Look for these four lines:
3. Log in to your hosting control panel (cPanel, Plesk, or similar) and navigate to the MySQL Databases or Database section.
4. Verify that the database name and username in wp-config.php exactly match what is listed in your hosting panel.
5. If you are not sure about the password, reset it from your hosting panel and update wp-config.php with the new password.
Note on DB_HOST: Most hosts use localhost, but some use a specific IP address or socket path. If localhost is not working, contact your hosting provider and ask for the correct database host value.
After saving any changes, reload your site. If the error is gone, you are done. If not, move to Step 2.
Your credentials may be correct, but the database server itself might be down or temporarily overloaded.
The fastest way to confirm this is to create a small test file. Using your FTP client or File Manager, create a new file in your WordPress root directory called testdb.php and paste in the following:
Replace DB_USER, DB_PASSWORD, and DB_NAME with your actual values from wp-config.php. Then visit yoursite.com/testdb.php in your browser.
Important: Delete testdb.php from your server immediately after testing. Leaving it live exposes your database credentials.
If your database server is running but the error persists, your database tables may be corrupted. This can happen after a server crash, a failed plugin update, or an interrupted WordPress update. WordPress has a built-in database repair tool that you can activate by adding one line to wp-config.php.
After the repair, reload your site. If it is back, you are good to go. If not, move to Step 4.
Some hosting plans (especially shared hosting) place a limit on the number of simultaneous connections to your database. If your site gets a traffic spike or if a poorly coded plugin is opening too many database connections at once, you can hit that limit and trigger this error.
Log in to your hosting control panel and look for a section labeled MySQL or Database Usage. Some hosts display the current connection count alongside the allowed limit. If you are at or near the limit, this is likely your problem.
If none of the above steps have resolved the error, the problem is almost certainly at the server level, outside your control as a site owner.
Common server-side causes your host can investigate:
What to tell your hosting provider:
When you open a support ticket, give them:
The more specific you are, the faster they can pinpoint the cause.
Once your site is back online, a few simple habits will significantly reduce the risk of this error recurring:
Use a plugin like UpdraftPlus or WP-DB Backup to schedule automatic database backups to an off-site location (Google Drive, Dropbox, or Amazon S3). If your database becomes corrupted again, you can restore a clean copy in minutes.
Use a free service like UptimeRobot to alert you by email or SMS the moment your site goes down. Catching an outage early shortens recovery time.
Hosts like Kinsta, WP Engine, and SiteGround run database health checks automatically and are far less likely to let the MySQL service crash without intervention. They also isolate your database from other users on the same server.
Plugins that are poorly coded or out of date are a leading cause of database corruption and connection overload. Remove plugins you do not actively use and keep all installed plugins updated.
Test all plugin updates, theme changes, and WordPress core updates on a staging site first. Most managed hosts provide a one-click staging environment. A failed update on staging is frustrating; the same failure on your live site can take it offline.
| Error Message | Most Likely Cause | First Step |
| “Error Establishing a Database Connection” on front end only | wp-config.php credentials wrong | Step 1 |
| Error on both front end AND wp-admin | Database server down or corrupted | Step 2 or 3 |
| wp-admin says “tables unavailable” | Database corruption | Step 3 |
| Error appears intermittently during traffic spikes | Connection limit exceeded | Step 4 |
| Error appeared after host migration | Wrong DB_HOST or credentials | Step 1 |
| Nothing above worked | Server-level issue | Step 5 |
The “Error Establishing a Database Connection” in WordPress is alarming, but it is rarely permanent. Work through the five steps in order:
In most cases, you will find the fix somewhere in Steps 1 through 3. With the right backup habits and a reliable hosting provider, you can make sure this error stays a rare event rather than a recurring headache.
If the issue still persists or you are not comfortable editing WordPress files and databases yourself, hiring an experienced WordPress developer can save time, prevent accidental downtime, and help identify deeper server-side or plugin-related problems quickly.