Fixing "Error establishing a database connection" in WordPress

6 min read Auf Deutsch lesen

Instead of your site, you get one stark sentence: “Error establishing a database connection”. WordPress can’t reach its database – and without the database it has nothing to show. The causes are limited; we’ll work through them in order.

1. Are the Credentials in wp-config.php Correct?

The most common trigger, especially after a server or hosting migration. Open wp-config.php in the root directory and check these four values:

define( 'DB_NAME', 'database_name' );
define( 'DB_USER', 'user' );
define( 'DB_PASSWORD', 'password' );
define( 'DB_HOST', 'localhost' );

DB_HOST is often localhost, but with some hosts it’s a dedicated server name or an IP with a port (e.g. db1234.host.com:3306). You’ll find the right value in your host’s database overview. A common stumbling block: special characters in the password that got altered when copied.

2. Is the Database Server Even Running?

Under heavy traffic or with tight resources, the database server can be briefly unreachable. Check whether other sites on the same hosting are affected, and look into phpMyAdmin – if you can log in there with the same credentials, you’ll know whether the problem is the credentials or the server. An exceeded storage or connection limit on your plan can also cut the connection; that usually shows in the hosting panel.

3. Is the Database Corrupted?

If the front end won’t load but the admin shows “One or more database tables are unavailable”, WordPress’s built-in repair often helps. Add to wp-config.php:

define( 'WP_ALLOW_REPAIR', true );

Then visit https://www.domain.tld/wp-admin/maint/repair.php, run the repair – and remove the line again afterwards, otherwise the page is reachable without a login.

4. Reset Credentials with Your Host

If the database password has changed or the user is locked, reset both in the hosting panel and enter them in wp-config.php. If you’re in the database anyway and still have login issues, Regain access to your WordPress admin takes it from there.

Quick Checklist

  1. Check the credentials in wp-config.php (name, user, password, host).
  2. Log into phpMyAdmin with the same details.
  3. Check other sites on the server → contact your host.
  4. Repair via WP_ALLOW_REPAIR (remove the line afterwards).

An overview of other error patterns is in the overview of WordPress errors.


If the connection stays down, or you’d rather not touch credentials and the database yourself: drop us a line – we’ll restore the connection.

Frequently Asked Questions

What does 'Error establishing a database connection' mean?

This message appears when WordPress can't reach its database – and without the database it can't show any content. The most common causes are wrong credentials in wp-config.php (often after a migration), a temporarily overloaded or unreachable database server, or corrupted tables. Usually the cause can be narrowed down in a few steps.

How do I fix the database connection error in WordPress?

In order: first check the four credentials in wp-config.php (DB_NAME, DB_USER, DB_PASSWORD, DB_HOST). Then test whether you can log into phpMyAdmin with the same details – if you can, it's not the credentials. Check whether other sites on the server are affected too (then it's the database server), and if in doubt repair corrupted tables via WP_ALLOW_REPAIR.

Where do I find the database credentials?

In the wp-config.php file in the root directory of your WordPress install. It contains DB_NAME, DB_USER, DB_PASSWORD and DB_HOST. The correct values – above all the right DB_HOST, which isn't always localhost – are in the database overview of your hosting panel. With some hosts it's a dedicated server name or an IP with a port.

What do I do if the WordPress database is corrupted?

If the admin shows a note that one or more tables are unavailable, the built-in repair helps. Add the line WP_ALLOW_REPAIR with the value true to wp-config.php, visit the repair page at wp-admin/maint/repair.php and run the check. Important: remove the line again afterwards, otherwise the repair page is publicly reachable without a login.

Daniel Nilges
Daniel Nilges

Founder & Full-Stack Developer

20+ years of web development experience. Specialised in Laravel, WordPress and custom software for mid-sized businesses.