Mubasher

Mubasher / CLIENT ACCESS

Your client area is next.

Contact Mubasher

No login details are collected on this trial.

What are you looking for?

Search services, hosting guides and company news.

← Blog & News

Technology ·

WordPress says "Error establishing a database connection": what to check

This message means WordPress cannot talk to its database. The cause is usually wrong credentials, a stopped database service or a damaged database.

Cover illustration: WordPress says "Error establishing a database connection": what to check

The message "Error establishing a database connection" replaces your whole site. It looks scary, but it has a short list of causes, and you can check them in order.

1. Credentials in wp-config.php

WordPress reads four values from wp-config.php: DB_NAME, DB_USER, DB_PASSWORD and DB_HOST. If you recently changed a database password, moved the site or restored a backup, one of these may no longer match. Compare them with the database and user shown in your hosting panel. DB_HOST is usually localhost, but some setups use a different host name.

2. Is the database service running?

If the credentials are right, test the connection from the panel, for example by opening the database tool. If the database server is down or overloaded, other sites on the same account may be affected too. On a VPS, check that the database service is running and that the server has free memory and disk space. A full disk is a common cause of a database stopping.

3. Damaged tables

WordPress can repair tables itself. Add define('WP_ALLOW_REPAIR', true); to wp-config.php, open yoursite.com/wp-admin/maint/repair.php and run the repair. Remove that line afterwards, because the page can be opened without a login while it is enabled.

4. Too many connections

A traffic spike, a bot attack or a badly behaved plugin can use up all database connections. Look at the access logs for repeated requests to wp-login.php, xmlrpc.php or search pages. Blocking the abusive source and adding caching reduces the load.

5. Restore as the last step

If a table is badly damaged, restore the database from a backup taken before the problem started.

Common questions

Is my data gone?

In most cases the data is still in the database. The message means WordPress cannot reach the database, not that the database is empty. Check the service and the credentials before you think about restoring.

The error appears only sometimes. Why?

Intermittent errors often point to limits: too many connections at busy times, a database service that restarts, or a server that runs out of memory. Look at traffic spikes and at the server resource graphs for the same time.

Can a plugin cause this?

Yes, but less often than wrong credentials or a stopped service. A plugin that runs heavy queries can push a small database over its connection limit, so review recently added plugins if the first checks are clean.

When to ask for help and what to send

Send support the exact wording of the error, the time it started, whether the site worked before a recent change, and which database name the site uses. Do not send the database password in a message. If the cause is the database service itself, support can check it from the server side, which you cannot do from the panel.

A realistic example

A site shows the database error after the owner changes the database password in the hosting panel. The password in wp-config.php was never updated. Copying the new value into the file brings the site back in a minute. Whenever you change a credential in one place, write down every other place that uses it.

Mistakes to avoid

  • Changing a password in the panel without updating wp-config.php.
  • Running repair on tables without a backup.
  • Restoring a backup before checking the service.

Quick checklist

  • Compare DB_NAME, DB_USER, DB_PASSWORD and DB_HOST in wp-config.php with the panel.
  • Check that the database service is running.
  • Try the repair option for damaged tables, after a backup.
  • Look at connection limits and traffic at the time of the error.
  • Restore from backup only when the cause is a damaged database.

Not sure which step applies? Tell us the time the problem began and what changed before it at support@mubasher.com.eg.