Black Friday: 60% off yearly plans with code BF2026, until November 30. See the deal

Troubleshooting

Error establishing a database connection in WordPress

This error means WordPress could not connect to its MySQL or MariaDB database, usually because the credentials in wp-config.php are wrong or the database server is down or full. Check the database name, user, password and host first, then ask your host about quota and server status.

The short answer
  • Four values in wp-config.php must match the database: name, user, password and host.
  • If they match, the database server itself is down, over quota or corrupted.
  • The whole site and wp-admin go down together, so uptime monitoring catches it quickly.

What can break the database connection?

Causes, symptoms and who can fix them
CauseHow to spot itWho fixes it
Wrong credentials in wp-config.phpStarted after a migration, password change or restoreYou
Wrong database hostWorks locally, fails on the new host; some hosts use a hostname other than localhostYou, using the host documentation
Database server down or restartingOther sites on the same server fail too; host status page shows an incidentYour host
Database quota or connection limit reachedHost reports the limit; problem comes and goes with trafficYou or your host
Corrupted tableswp-admin shows a different message offering repair, or only some pages failYou, with the repair tool

How do you diagnose it, in order?

  1. 01

    Check whether wp-admin shows the same error

    If /wp-admin shows a different message about repairing the database, jump to the repair step below.

  2. 02

    Compare wp-config.php with the host database panel

    Confirm DB_NAME, DB_USER, DB_PASSWORD and DB_HOST exactly. A trailing space or a copied quote mark is enough to fail.

  3. 03

    Test the credentials outside WordPress

    From a shell on the same server, run the mysql command shown below. If it fails, the credentials or server are the problem, not WordPress.

  4. 04

    Ask your host about status and quota

    WordPress documentation advises asking the host whether the database server is down or the account hit its database quota.

  5. 05

    Reset the database password if needed

    Set a new password in your host panel, then update DB_PASSWORD to match.

  6. 06

    Run the repair tool

    Add the repair constant, open the repair URL, then remove the constant (see below).

  7. 07

    Scan for compromise

    If everything checks out, WordPress documentation suggests scanning the site, because an attacker or malware can alter credentials or data.

How do you test the connection and run the repair tool?

Shell test, then wp-config.php repair constant
# Test credentials from the server (replace the placeholders)
mysql -h DB_HOST -u DB_USER -p DB_NAME

// wp-config.php: enable only while repairing
define( 'WP_ALLOW_REPAIR', true );
// then open: https://example.com/wp-admin/maint/repair.php

WordPress states the repair script needs no login, so set the constant back or delete it once the repair is done. See the wp-config.php reference.

Check the host before editing files

If several sites on the same account fail at once, the database server is the common factor. Editing wp-config.php will not help, and a wrong edit can turn a host outage into a second problem. Check the host status page first.

What should you confirm before changing anything?

  • A fresh backup of the files exists, and a database dump if the server still lets you take one
  • Whether the problem affects one site or every site on the same hosting account
  • Whether anything changed shortly before: a migration, a password rotation, a host upgrade or a restore
  • That the database user still has permission on the database, not only a correct password

Common questions

What does "error establishing a database connection" mean?

It means WordPress could not open a connection to its MySQL or MariaDB database. WordPress needs the database to build every page, so the front end and wp-admin both fail. Wrong credentials and an unavailable database server are the two main causes.

Can a plugin cause this error?

Rarely directly. The error comes from WordPress core failing to connect, which happens before plugins run. A plugin can exhaust database connections or fill a quota, which then makes the connection fail, but the first checks are credentials and host status.

Is my data lost when this error appears?

Usually not. The data sits in the database and is unreachable only while the connection fails. Take a backup as soon as you can reach the database, and keep one before any repair, because repair changes tables.

Why does the error appear only sometimes?

An intermittent error points to the database server hitting a limit under load, restarts, or a shared host with noisy neighbors. Ask your host for connection limits and logs, and monitor from several regions so you see exactly when it fails.

Watch your domains automatically

Aepto monitors expiry, DNS, SSL and uptime for every domain you own and alerts you when something changes. Free for 3 domains.