New: Get a complete business website live in 48 hours for $699 flat. See how it works →

HomeBlog › Troubleshooting

Troubleshooting

Error Establishing a Database Connection in WordPress: Every Cause and Fix

By the 5digital Engineering Team · Updated August 2026

"Error establishing a database connection" means WordPress cannot talk to its database. The cause is one of four things: wrong credentials in wp-config.php, a crashed database server, a corrupted database, or an overloaded host. Work through them in that order and most sites are back within 20 minutes.

Option 1: Do it yourself

Follow the steps in this guide. Free, and typically 30 minutes to a few hours of careful work.

Option 2: Just contact us

Skip every step below. $49/mo and it is sorted, or WhatsApp us right now.

Last updated: August 2026

First, check one thing

Visit yourwebsite.com/wp-admin. If the admin shows a different message such as "One or more database tables are unavailable," you have a corrupted database, so jump to the repair step below. If it shows the same connection error, continue in order.

Fix 1: Verify the database credentials

Open wp-config.php via your host's file manager and find four lines: DB_NAME, DB_USER, DB_PASSWORD and DB_HOST. Compare them against the actual database shown in your hosting panel's database section. This error very often appears right after a migration, a hosting change or a password reset, because the config still points at the old details. Correct any mismatch and reload.

Fix 2: Check whether the database server is down

In your hosting panel, look for a service status or try opening phpMyAdmin. If phpMyAdmin will not connect either, the database service itself is down and this is your host's problem: open a ticket stating "MySQL appears down, phpMyAdmin unreachable." On a VPS, restarting the database service fixes the common case where it crashed from memory exhaustion.

Fix 3: Repair a corrupted database

Add this line to wp-config.php just above the "That's all, stop editing" comment: define('WP_ALLOW_REPAIR', true); then visit yourwebsite.com/wp-admin/maint/repair.php and click Repair Database. When it finishes, remove that line immediately, because the repair page needs no login and should never stay enabled.

Fix 4: The overload case

If the error comes and goes, especially during traffic peaks, your database is being refused connections because the server is out of resources. Shared hosting caps concurrent connections tightly. Short term, ask the host to raise limits; real term, this is the classic sign you have outgrown shared hosting, and a small VPS ends the problem permanently.

If nothing above worked

Restore last night's backup to rule out corruption you cannot see, and check whether the site was hacked, since injected code sometimes corrupts or overloads the database. Our guides on restoring from backup and safe recovery and malware removal cover both branches.

Preventing round two

The unglamorous fixes prevent almost all repeats: daily verified backups, database optimization so bloat never grows into corruption, monitoring that alerts within a minute of the first failure, and hosting sized for your actual traffic. All four are standard inside our maintenance plans, which is why this error is something our clients read about rather than experience.

FAQ

Did I lose my content? Almost certainly not. The content sits safely in the database; WordPress just cannot reach it. Even in corruption cases, repair or a recent backup recovers everything.

Why did it happen with no changes on my end? Hosts change things too: password rotations, server migrations, PHP or MySQL upgrades. "Nothing changed" usually means "nothing changed that you did."

The error only shows sometimes. Why? Intermittent errors are resource exhaustion: too many connections at peak. That is a hosting capacity issue, not a code issue.

How fast can a professional fix this? With hosting access, typically 15 to 45 minutes. It is one of the most common one-time fixes we handle.

You do not have to do any of this yourself

Skip the steps above. Our engineers handle security, updates, speed, backups and fixes for you, with a 12-minute average response and a 99.99% uptime target.

Fix It For Me, $49/mo →Talk to an engineer