home / website errors / error-establishing-a-database-connection

[ REPAIR GUIDE ] WEBSITE ERRORS

How to fix "Error establishing a database connection" in WordPress

ERROR DETECTED >Error establishing a database connection

UPDATED NOVEMBER 20262 MIN READ7 FIXES

QUICK FIX

Site owners should first confirm the database name, username, password and host in wp-config.php match what the hosting control panel shows. If they match, ask the host whether the database server is down or over its limits.

What it means

This WordPress message means the site could not connect to the MySQL or MariaDB database that stores its posts, pages and settings, so it cannot build any page. It is the site owner's problem: wrong login details in wp-config.php, a database server that is down or overloaded, or damaged database tables. Visitors cannot fix it and can only wait or let the owner know.

Common causes

  • Wrong database name, username, password or host in wp-config.php
  • The database server is down, restarting or overloaded
  • The database user lost its password or permissions
  • Damaged or corrupted database tables
  • The hosting account hit its database or storage limit
  • A hacked or modified wp-config.php file

How to fix it

Work down the list. Each fix is safe to try before moving on to the next.

FIX 01Reload laterEASY

  1. Wait a few minutes.
  2. Press F5 on Windows or Command + R on a Mac to reload.

Why it helps: If the database server was briefly overloaded or restarting, the site comes back on its own.

FIX 02Let the site owner knowEASY

  1. If the error stays for more than a short while, contact the site through its email or social media.
  2. Tell them the time you first saw the message.

Why it helps: Nothing on a visitor's device causes this error, so only the owner can fix it.

// RUN THIS SITE? FIXES FOR SITE OWNERS

FIX 03Check the database details in wp-config.phpMEDIUMSITE OWNERS

  1. Open your host's File Manager or connect with SFTP and download a backup copy of wp-config.php from the WordPress root folder.
  2. Open it and find the lines for DB_NAME, DB_USER, DB_PASSWORD and DB_HOST.
  3. In your hosting control panel (for example MySQL Databases in cPanel), confirm the database name and user exist and the user is assigned to that database.
  4. Check that DB_HOST matches what your host says; it is often localhost, but some hosts use a separate hostname.
  5. Fix any mismatch, save the file and reload the site.

Why it helps: A typo or changed value here is the most common reason WordPress cannot log in to the database.

FIX 04Reset the database user's passwordMEDIUMSITE OWNERS

  1. In your hosting control panel, open the database users section.
  2. Set a new strong password for the user listed in DB_USER.
  3. Make sure that user has all privileges on the database named in DB_NAME.
  4. Put the same new password in DB_PASSWORD in wp-config.php and save.

Why it helps: If the details look right but still fail, the stored password or permissions may not match.

FIX 05Ask your host whether the database server is upEASYSITE OWNERS

  1. Check your host's status page for database or server outages.
  2. Try opening phpMyAdmin from your control panel; if it also cannot connect, the database server is likely down.
  3. Contact your host and ask whether the database server is down, overloaded, or over a size or connection limit on your account.

Why it helps: When the details are right, the database server itself or an account limit is the next most likely cause.

FIX 06Repair the database tablesADVANCEDSITE OWNERS

  1. Back up the database first using your host's backup tool or phpMyAdmin export.
  2. Add define( 'WP_ALLOW_REPAIR', true ); to wp-config.php above the line that says to stop editing.
  3. Visit yoursite.com/wp-admin/maint/repair.php and choose Repair Database.
  4. Warning: this page works without logging in, so remove the WP_ALLOW_REPAIR line as soon as the repair finishes.

Why it helps: Corrupted tables can stop WordPress from loading even when the connection details are correct.

FIX 07Check for a hacked or changed siteADVANCEDSITE OWNERS

  1. Compare wp-config.php with your last known good backup for unexpected changes.
  2. Look in your hosting panel for unfamiliar database users or recently changed files.
  3. If anything looks wrong, change your hosting, database and WordPress passwords and ask your host to scan the account.

Why it helps: WordPress's own guidance says a compromised site can cause this error once settings and the server are ruled out.

Check it's fixed

  • The home page and wp-admin both load.
  • You can log in and see your posts and pages.
  • If you enabled WP_ALLOW_REPAIR, it has been removed from wp-config.php.

When to get help

If the details in wp-config.php are correct and phpMyAdmin cannot connect either, the database server is the problem and only your hosting provider can fix it. Contact them with the time the error started.

Questions

Did I lose my content?

Usually not. The error means WordPress cannot reach the database, not that the data is gone. Once the connection works, your posts normally reappear.

Why does wp-admin show a different message?

WordPress may say one or more tables are unavailable and the database may need repairing. That points to damaged tables rather than wrong login details.

Why did this start without me changing anything?

The database server may be down or overloaded, your host may have changed something, or the account may have hit a limit. Ask your host.

Related fixes

Still stuck?

Paste the exact message and the repair bot will find the closest fix, or search it on Google, Microsoft, Apple, Reddit and YouTube.

Sources