How to Fix “Error Establishing a Database Connection” in WordPress (2026 Guide)

QUICK ANSWER
The “Error Establishing a Database Connection” in WordPress means WordPress cannot connect to your MySQL database. The most common causes are wrong database credentials in wp-config.php, a corrupted database, or your database server being down. In most cases, you can fix it in under 10 minutes.

Fast fix: Check your wp-config.php credentials first. That solves this error 70% of the time.

If your WordPress site is showing this error right now, don’t panic. You haven’t lost your data. Your posts, pages, and files are all still there — WordPress just can’t reach the database at this moment.

This guide walks you through every fix, starting with the simplest and most common first.

Table of Contents

  • What causes this error?
  • Step 1 — Check your database credentials
  • Step 2 — Repair your WordPress database
  • Step 3 — Check if your database server is down
  • Step 4 — Check for a corrupted wp-config.php
  • Step 5 — Contact your hosting provider
  • Frequently asked questions
  • How to prevent this error in future

What Causes the “Error Establishing a Database Connection” in WordPress?

WordPress stores all your content — posts, settings, users — inside a MySQL database. When WordPress cannot connect to that database, it throws this error instead of loading your site.

There are four main causes:

CauseHow Common?Difficulty to Fix
Wrong database credentialsVery common (70%)Easy — 2 min
Corrupted databaseCommon (20%)Easy — 5 min
Database server downLess commonMedium
Corrupted wp-config.phpRareMedium

TIP  Work through the steps below in order. Each one takes under 5 minutes. Most people fix this error at Step 1 or Step 2.

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

This fixes the error in the majority of cases. Your database credentials may have changed (for example, after a hosting migration or your host reset your database password).

How to access wp-config.php

  1. Log in to your hosting control panel (cPanel, Plesk, etc.)
  2. Open File Manager and navigate to your website’s root folder (usually public_html)
  3. Find the file named wp-config.php and open it

What to look for

Find these four lines in the file:

define( ‘DB_NAME’, ‘your_database_name’ );

define( ‘DB_USER’, ‘your_database_username’ );

define( ‘DB_PASSWORD’, ‘your_database_password’ );

define( ‘DB_HOST’, ‘localhost’ );

How to verify the credentials are correct

  • In cPanel, go to MySQL Databases
  • Check the database name — it must exactly match DB_NAME (including the prefix, e.g. username_wpdb)
  • Confirm the username exists and is assigned to that database
  • If you’re unsure of the password, create a new one and update it in both MySQL Databases and your wp-config.php

NOTE  DB_HOST is almost always ‘localhost’. Only change it if your hosting provider has given you a different database host address.

Step 2: Repair Your WordPress Database

If your credentials are correct but the error persists, your database may be corrupted. WordPress has a built-in repair tool for this.

Enable the database repair tool

  • Open wp-config.php again
  • Add this line just before the line that says “That’s all, stop editing!”:

define( ‘WP_ALLOW_REPAIR’, true );

  1. Save the file

Run the repair

  1. Visit this URL in your browser (replace yourdomain.com with your actual domain):

https://yourdomain.com/wp-admin/maint/repair.php

  1. Click Repair and Optimize Database
  2. Wait for it to complete — you will see a success message
  3. Important: Go back to wp-config.php and remove the WP_ALLOW_REPAIR line after the repair is done

WARNING  Never leave WP_ALLOW_REPAIR enabled permanently. Anyone can run the repair tool without logging in while it is active.

Step 3: Check if Your Database Server is Down

Sometimes the problem is not your site at all — it is your hosting server’s MySQL service.

How to check

  • Check your hosting provider’s status page (search “[your host] status page” — most major hosts have one)
  • Log in to cPanel and try to open phpMyAdmin. If it fails to load, MySQL is down on the server.
  • Check if your other WordPress sites on the same host are showing the same error

If MySQL is down on the server side, the only fix is to contact your hosting support. This is a server-level issue they must resolve. Most hosts fix this within 1-2 hours.

Step 4: Check for a Corrupted wp-config.php File

Rarely, the wp-config.php file itself becomes corrupted — for example after a bad plugin update or a failed migration. Signs include:

  • You can access wp-admin fine, but the front end shows the error
  • Your credentials are definitely correct but the error persists

Fix: Regenerate wp-config.php

  1. Download a fresh copy of WordPress from wordpress.org
  2. Inside the zip, find wp-config-sample.php
  3. Upload it to your site root and rename it to wp-config-new.php
  4. Open it and fill in your database details (same values as your old wp-config.php)
  5. Also copy over your security keys from the old file (the lines starting with AUTH_KEY, SECURE_AUTH_KEY, etc.)
  6. Rename your old wp-config.php to wp-config-backup.php
  7. Rename wp-config-new.php to wp-config.php
  8. Reload your site

Step 5: Contact Your Hosting Provider

If none of the above steps resolved the error, contact your host’s support team. Give them this information to speed up the resolution:

  • The exact error message you’re seeing
  • When the error first appeared and what changed before it (update, migration, plugin install)
  • Confirmation that you’ve already checked your wp-config.php credentials
  • Whether the error appears on admin, front end, or both

Most major hosts (SiteGround, Bluehost, Kinsta, Cloudways, WP Engine) offer 24/7 live chat and can usually diagnose this within 15 minutes.

Frequently Asked Questions

Is my data lost when I see this error?

No. The “Error Establishing a Database Connection” does not delete or affect your data. Your database still exists — WordPress simply cannot connect to it right now. Once the connection is restored, your site returns to normal.

Can a plugin cause this error?

Directly, no. Plugins do not affect the database connection credentials. However, a plugin can fill up your disk space or overload the server, which can bring down the MySQL service and cause this error indirectly.

Why does this error only show on the front end but not the admin?

WordPress uses separate connection checks for the front end and wp-admin. If only one side shows the error, your database is partially accessible. Run the repair tool (Step 2) first — this usually resolves it.

How long does it take to fix?

In most cases, 2 to 10 minutes. Checking and correcting wp-config.php credentials (Step 1) takes about 2 minutes. Running the repair tool (Step 2) takes about 5 minutes. If the issue is server-side, resolution depends on your hosting provider.

Does this error affect SEO?

If your site is down for a short time (under 4 hours), Google typically does not penalize you. For extended outages, Google may de-index pages. Fix this error as quickly as possible, and your rankings will return to normal once the site is back online.

How to Prevent This Error in the Future

Once your site is back online, take these steps to prevent the error from recurring:

  • Set up automated daily backups — use UpdraftPlus (free) and send backups to Google Drive
  • Use a staging site before making major changes (migrations, host transfers, theme updates)
  • Enable uptime monitoring — UptimeRobot (free) will email you the moment your site goes down
  • Keep a copy of your database credentials in a secure password manager
  • Ask your host about database server stability — if this error happens repeatedly, it may be time to switch hosts

Wrapping Up

The “Error Establishing a Database Connection” looks scary, but in most cases it is a simple credentials mismatch that takes two minutes to fix. Work through the steps in order, and your site will be back online quickly.

If you got stuck at any step or the error came back, leave a comment below and we will help you diagnose it.

Leave a comment