Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4862 pages

Help for owners

My website just says Error establishing a database connection

Short answer

Error establishing a database connection means WordPress cannot reach the database that holds your pages, users and orders. WordPress's own guide says the usual cause is a wrong database name, username, password or host in wp-config.php. It also lists hosting problems, such as a database shut down for going over its quota or a server that is down, and hacked sites.

  • Written for business owners
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Does this sound like your situation?

  • Every page of my WordPress site shows one white page with this error.
  • The error appeared right after the site moved to a new host.
  • It started after someone changed the hosting or database password.
  • The site comes back for a while and then the error returns.

Why does this happen?

  1. Wrong details in wp-config.php

    WordPress's guide to common errors says this message is usually caused by an error in the wp-config.php file. The four values to check are the database name, the database username, its password and the database host. A site move or a password change at the host often leaves one of them out of date.

  2. A problem at the web host

    The same guide lists two hosting problems: the database has met its quota and been shut down, or the server is down. Neither one is fixed by changing WordPress files, which is why the host comes first.

  3. A compromised site

    WordPress says that if the settings and the host check out, the site may have been hacked, and suggests scanning it for compromise.

  4. Too many visitors for the database

    On small hosting plans, a burst of traffic or a stuck plugin can use up the database connections the plan allows, so the error comes and goes with load. Your host's logs show whether that is happening.

What can I do about it today?

  1. Check your host's status and noticesLook at the host's status page and the messages in your hosting account for an outage, a suspended database or a quota warning.
  2. Ask the host two direct questionsIs the database server for my site running, and is my database within its quota. Ask them to quote what the logs show.
  3. Write down what changed recentlyA move to a new host, a new password, a plugin or theme update, a new domain. Hand that list to whoever fixes it.
  4. Back up wp-config.php before any editIf someone is about to change wp-config.php, download a copy of the original first, so a typo can be undone in seconds.
  5. Hold off on restoring a backupRestoring an old backup over a database that is only unreachable can wipe recent orders, comments and sign-ups. Find the cause first.

When should I bring someone in?

  • Your host reports no fault on its side and the wp-config.php values look correct.
  • The site is a store and orders are being lost while it is down.
  • You see unknown admin users, strange files or redirects alongside the error.

How do I handle it?

  1. Test the connection from the serverI connect to the database with the exact details in wp-config.php from the web server itself, which shows at once whether the details or the database are the problem.
  2. Read the host and database logsI check for quota limits, crashed tables or connection limits being hit, and fix or escalate with the host.
  3. Rule out a compromiseIf the setup is sound, I check for changed core files, unknown admins and injected code before the site goes back online.
  4. Prevent a repeatI set up uptime checks and database backups you can restore from, and record the working connection details somewhere safe.

The price depends on what I find, so I quote in writing after a short discovery call. Tell me what is happening and I reply within 24 hours.

What do owners ask about this?

What does error establishing a database connection mean?

It means WordPress tried to open its database and could not. The pages exist in the database, but the site cannot read them until the connection works.

Is my data gone?

Not usually. The error is about the connection. Confirm with your host that the database is still there before anyone restores or deletes anything.

How do I fix the database connection error after moving WordPress?

After a move, check the four values in wp-config.php against the new host's database details, since WordPress names those as the usual cause. Check the database host value as carefully as the password.

Was my site hacked?

It is possible. WordPress lists a compromised site as a cause once settings and hosting are ruled out, so check those two first.

Sources

For your developer: the technical fixes

Related help

Next step

Want this off your desk?

Send me a few lines on where things stand. I reply within 24 hours.