Troubleshooting guide · wordpress · Published 2026-08-14 · 3 min read

Error establishing a database connection

Fix WordPress "Error establishing a database connection". Check the database server, wp-config credentials, host string, and connection limits in order.

Symptoms

The page says "Error establishing a database connection" or "Error connecting to database." It is usually the whole site, not one page. Sometimes it appears after a host move, a MySQL upgrade, or a config edit; sometimes it appears all at once for no obvious reason.

Common causes

How to fix

  1. Check whether the database server is reachable from the command line or a host tool such as phpMyAdmin using the same credentials WordPress uses. If you cannot connect there either, the problem is the server or the credentials, not the site.
  2. Verify the credentials. Edit wp-config.php with a text editor, not the browser editor. Confirm each constant against your host's provided values, including the host value, which is often not localhost.
  3. Test with a database client or a short script. A one-line PHP file that calls mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME) prints the real error instead of the generic message. Delete it after testing.
  4. Restart the database service if the host offers restart access, or raise an incident with the host if they run it.
  5. Check for an unmatched table prefix: the value of $table_prefix in wp-config must match the prefix of the tables in the database (usually wp_).
  6. Be careful with downtime during a move. If you changed hosts or IPs, the old and new server may be fighting over the connection, or a firewall may be blocking the new database host.
  7. Review resource limits if the error is intermittent under load. Some shared hosts kill long-running or too many concurrent connections.

Prevention

Need a website built, fixed, optimised, migrated or replaced?

This technical resource is written by CSMBAC, a small design and development studio. If you would rather hand the problem to a professional, the website service page explains how we build enquiry-ready websites.

Explore website services