Database connection

Error Establishing a Database Connection

Fix the WordPress database connection error by checking wp-config.php, database credentials, MySQL/MariaDB health, and hosting changes.

Start here

Quick Answer

Check database credentials, DB host, database user privileges, MySQL or MariaDB service health, and table prefix first. In WordPress, compare DB_NAME, DB_USER, DB_PASSWORD, DB_HOST, and $table_prefix in wp-config.php with the hosting control panel.

What this means in WordPress

This error means WordPress could not establish a connection to the configured database. The usual causes are wrong DB_NAME, DB_USER, DB_PASSWORD, or DB_HOST, a database server outage, missing user privileges, a migration mismatch, or connection limits on the host.

Safe credential checks

Compare wp-config.php with your hosting panel or deployment secrets. Do not paste DB_PASSWORD, salts, or secret keys into public tickets or screenshots. If you need to share the file with support, redact the password and salts first. Use the wp-config.php repair guide when credentials changed during migration.

When it is not a credential issue

If credentials are unchanged and the error is intermittent, check MySQL or MariaDB health, connection limits, disk pressure, host maintenance, and slow queries. The database health guide separates service health from WordPress configuration.

Diagnosis

Symptoms

  • WordPress displays “Error establishing a database connection.”
  • Admin and public pages fail while static assets may still load.
  • Database login, host, user privileges, or service health changed recently.

Common causes

  • Wrong database name, user, password, host, port, or socket.
  • Database user lacks privileges on the WordPress database.
  • MySQL or MariaDB is stopped, overloaded, out of disk, or rejecting connections.
  • Table prefix does not match the installed WordPress tables.
  • Recent migration or hosting change pointed the app at the wrong database.

Diagnostic Checklist

  1. Compare wp-config.php database constants with the hosting panel.
  2. Test database login from the web server when possible.
  3. Check MySQL or MariaDB service status, connection limits, and disk space.
  4. Confirm table prefix and required WordPress tables exist.

Fixes

Verify wp-config.php database settings

  • 10 minutes
  • Risk: medium
  • Site owner
  • WordPress, MySQL

Fix the most common WordPress database connection mismatch.

  1. Open wp-config.php from the active site root.
  2. Compare DB_NAME, DB_USER, DB_PASSWORD, and DB_HOST with the hosting control panel.
  3. Check whether the host needs a port or socket.
  4. Save with original permissions and clear object cache if used.
Expected result

WordPress can authenticate to the intended database.

If it failed

If credentials are correct, test database service health and user privileges next.

Verify

Reload the site and wp-admin login.

Rollback

Restore the previous wp-config.php if the edit made the error worse.

Was this fix useful?

Check database service and user privileges

  • 15 minutes
  • Risk: medium
  • Host admin
  • MySQL, MariaDB

Find service outages, exhausted connections, or permission problems.

  1. Confirm MySQL or MariaDB is running.
  2. Test login using the WordPress database user from the web server.
  3. Check connection limits, disk space, and database error logs.
  4. Confirm the user has read/write privileges on the WordPress database.
Expected result

The database accepts connections and WordPress has required privileges.

If it failed

If login works but WordPress fails, inspect table prefix and application logs.

Verify

Load public and admin pages while watching database logs.

Rollback

Undo temporary privilege changes that exceed the application need.

Was this fix useful?

Platform notes

On managed WordPress hosting, database hostnames and passwords can change during migrations. On VPS setups, service health and local socket paths are as important as credentials.

FAQ

Is this always a WordPress problem?

No. WordPress displays the message, but the failure may be database service health, credentials, privileges, DNS, or hosting configuration.

Should I repair tables first?

Only after credentials and service health are confirmed and after taking a backup. Most connection errors are not table corruption.

Review notes

Last reviewed
2026-05-05
Reviewed by
FaultForge Editorial Team, Web operations reviewer
Tested on

WordPress wp-config.php database settings, MySQL and MariaDB service health checks, credential validation, and managed-hosting database status review.

Sources