Error Establishing a Database Connection in WordPress: The Complete Fix (With a Real 3AM Case)

Published on August 14, 2026

If your WordPress site is showing a blank white screen with the message “Error establishing a database connection,” your site is currently down for every visitor, including you. This guide walks through every real cause of this error and the exact fix for each one, based on a live client emergency I handled at 3AM.

What “Error Establishing a Database Connection” Actually Means

WordPress stores none of your content on the page itself. Every post, page, setting, and plugin option lives in a MySQL database, and WordPress pulls that data through connection details stored in your wp-config.php file. When that connection fails for any reason, WordPress can’t retrieve anything, so instead of your site, visitors see this one error message.

The message is generic on purpose. It can mean several different things are wrong, which is exactly why guessing and editing files randomly is the worst way to fix it.

The Real Case: A 3AM Emergency Message

It was almost 3AM when my phone lit up. Two messages arrived back to back, one on Upwork and one on email, from the same client:

“I have a bit of an emergency – my website is not working. It shows database error. Can you address this as soon as possible please.”

I opened the site. Same error every WordPress developer eventually sees: a blank page and “Error establishing a database connection.”

The instinct at 3AM is to panic. Start editing database credentials, second-guess wp-config.php, maybe even consider restoring a backup half-asleep. That instinct is exactly how a five-minute problem turns into a five-hour disaster.

So instead, I worked through the cause systematically, starting with the simplest possibility first.

The Most Common Causes (Check in This Order)

Before touching any file, it helps to know what’s actually likely to be wrong. In order of how often each one is the actual cause:

  1. The server or database service itself isn’t running. Nothing is wrong with your WordPress files at all; the service just needs to be restarted.
  2. Incorrect database credentials in wp-config.php. Very common after a site migration or a host change.
  3. Insufficient database user privileges. The credentials are correct, but the database user doesn’t have permission to access the database.
  4. A corrupted database. Usually from a failed plugin update, an interrupted migration, or direct database editing.
  5. Corrupted core WordPress files. Rare, but possible after an incomplete update or a malware infection.

In my client’s case, it was cause #1. Here’s how I found that out, and how you can check it too.

Step 1: Check If the Server/Database Service Is Running

This step gets skipped constantly, and it’s the fastest one to check. If the database service on your server has stopped, which can happen from a resource limit, a crash, or routine maintenance, WordPress will show this exact error even though nothing is actually broken.

How to check, depending on your hosting panel:

  • cPanel hosting: Log in to cPanel and look for “Service Status,” or check with your host’s status page. Some hosts also show this under “MySQL/MariaDB” in the database section.
  • Hostinger, GoDaddy, or similar simplified panels: Go to your hosting dashboard’s Websites section. If there’s no direct “restart service” option, contact live chat support and ask them to check if MySQL or the database service is running. This takes most hosts under two minutes to verify.
  • SiteGround: Check Site Tools under Statistics, or contact support directly, since SiteGround manages database services at the infrastructure level.
  • WHM (Web Host Manager, common on agency/managed hosting): Log in to your WHM panel (often at a URL like cpanel.yourdomain.com). Click “Admin Area” in the top right corner. From there, go to the Admin Area / Users section. In the left sidebar, look for an “Instance” option, this shows the status of core services including MySQL. If MySQL shows as stopped, restart it directly from that panel. This is exactly what resolved the case in this article: MySQL had stopped, and a simple restart from the Instance panel brought the site back within minutes.
  • WHM or a VPS with SSH access (no admin panel): Connect via SSH and run systemctl status mysql or service mysql status. If it shows “inactive” or “failed,” restart it with systemctl restart mysql.

In my client’s case, the service had stopped. One restart, no code touched, and the site was back within a minute.

If the server is running fine, move to Step 2.

Step 2: Check Your Database Credentials in wp-config.php

If the service is running but the error persists, open wp-config.php in your site’s root folder and verify these four values against what your hosting panel shows for your database:

define( 'DB_NAME', 'your_database_name' );
define( 'DB_USER', 'your_database_username' );
define( 'DB_PASSWORD', 'your_database_password' );
define( 'DB_HOST', 'localhost' );

This is the most common cause after migrating a site to a new host. The old credentials get carried over but no longer match the new server. Compare each value character-by-character with what’s shown in your hosting panel’s database section.

Step 3: Check Database User Privileges

Correct credentials don’t help if the database user isn’t actually authorized to access that specific database. In cPanel, this is under MySQL Databases → check that your database user is listed under “Users in Database” with All Privileges checked. If not, add the user and grant full privileges.

Step 4: Check for a Corrupted Database

If your WordPress dashboard (not the front end) shows a message like “One or more database tables are unavailable. The database may need to be repaired,” your database has some corrupted tables. You can attempt an automatic repair by adding this line to wp-config.php:

define( 'WP_ALLOW_REPAIR', true );

Then visit yoursite.com/wp-admin/maint/repair.php to run the repair tool. Remove this line from wp-config.php once you’re done. Leaving it in is a security risk, since the repair page has no login requirement.

Step 5: Check for Corrupted Core Files

If nothing above resolves it, your WordPress core files themselves may be corrupted or altered, sometimes from an interrupted update, sometimes from malware. Re-uploading a clean copy of WordPress core files (without touching your wp-content folder) resolves this in most cases. If you suspect malware specifically, this is the point to run a security scan before doing anything else.

What the Client Said Afterward

A few days later, the client sent this over:

“Junaid is a lifesaver and a miracle worker! For a business owner, it’s a disaster when the website suddenly goes down. Even though it was 4:00 AM in the morning for him, he immediately responded to the emergency situation. He was able to diagnose that the MySQL database service had stopped working. He was able to reset it and get my website working again in less than an hour. Thank you!”

That message matters more than the fix itself. Clients don’t remember how technical the solution was. They remember how quickly and calmly it got handled.

Frequently Asked Questions

Does this error delete my content?
No. In almost every case, your posts, pages, and data are untouched. The site just can’t reach the database that stores them. Content loss is rare and usually only happens with severe, unaddressed database corruption.

Will this error hurt my Google rankings?
A short outage of a few hours typically causes no lasting SEO damage. If the error persists for days, search engines may temporarily drop indexed pages, so it’s worth fixing quickly rather than leaving it.

I don’t have server or SSH access? What do I do?
Contact your hosting provider’s support and ask them directly to check whether the MySQL/database service is running on your account. Most hosts can confirm and fix this in under 10 minutes.

Can I fix this myself without a developer?
Steps 1 through 3 (checking server status and credentials) are safe to check yourself. Steps 4 and 5 involve editing core files and database repair tools. If you’re not comfortable there, it’s worth getting a developer to check it rather than risking further corruption.


I work with businesses and agencies on WordPress development, plugin builds, and site fixes, including the kind that show up at 3AM. If your WordPress site is showing this error right now, feel free to reach out.