WordPress: Error Establishing a Database Connection

WordPress: Error Establishing a Database Connection error guide banner

DIRECT ANSWER

WordPress displays “Error Establishing a Database Connection” when it cannot connect to its configured MySQL or MariaDB database. Check `DB_NAME`, `DB_USER`, `DB_PASSWORD`, and `DB_HOST` in `wp-config.php`, then confirm the database server is available and the user can access that database. Corrupted tables are possible, but they should be investigated only after connection and privilege checks pass.

Key takeaways

  • Compare DB_NAME, DB_USER, DB_PASSWORD, and DB_HOST in wp-config.php with the current values from your hosting provider.
  • Confirm that MySQL or MariaDB is running and reachable; shared-hosting users should check the hosting panel or contact the host.
  • Test the exact connection details through phpMyAdmin or the MySQL command line to separate a WordPress configuration issue from a database-server issue.
  • Verify that the configured user is assigned to the intended WordPress database and has the required privileges.
  • Back up the database before checking or repairing tables, and do not treat REPAIR TABLE as a universal fix.
Reviewed 2026-09-25 WordPress Errors
SA

Site Administrator

Last reviewed: September 25, 2026

What this error means & how to recognize it

  • The site displays only “Error establishing a database connection,” often on every front-end page.
  • /wp-admin/ is also unavailable because it uses the same database connection.
  • The error may begin after a migration, hosting change, database restore, manual wp-config.php edit, password reset, or database-server restart.
  • If only selected pages fail while other database-backed pages work, the issue may be page-, plugin-, theme-, or query-specific rather than a complete database connection failure.

Root causes, ordered by likelihood

  1. Incorrect credentials in wp-config.php — DB_NAME, DB_USER, DB_PASSWORD, or DB_HOST no longer matches the current database configuration. This is especially common after a migration, restore, password change, or manual edit.
  2. An unavailable MySQL or MariaDB server — the service may have stopped, crashed, or become unavailable because of a hosting resource problem.
  3. The wrong database host — localhost may be incorrect when the database runs on another server or container, while a remote host value may no longer match the current environment.
  4. Missing database-user privileges — the user may exist but not be assigned to the WordPress database or may lack the privileges needed to use it.
  5. Corrupted database tables — an interrupted write, unclean shutdown, or disk problem can damage tables, but this is generally less likely than a configuration or availability problem.

How to fix it

1Does the error affect the front end and /wp-admin/?2Is MySQL or MariaDB running and reachable?3Do the exact settings connect through phpMyAdmin or theMySQL command line?4Does the user have access to the intended database?5Does the error remain after all checks pass? Contact thehost with the approximate start time, service status,direct-connection result, and whether /wp-admin/ alsofails. Do not send passwords.
Diagnostic flow at a glance — full detail in the steps below.

1. Confirm the scope of the failure

Open the public site and /wp-admin/. If both show the connection error, continue with the database checks below. If only one page or function fails, inspect the specific plugin, theme, query, or application error instead of assuming the entire database connection is unavailable.

2. Check whether MySQL or MariaDB is running

On a VPS or dedicated server where you are responsible for service management, check the relevant service status. These commands are read-only and require shell access:

bash
systemctl status mysql

If the server uses MariaDB, check:

bash
systemctl status mariadb

On shared or managed hosting, use the hosting panel’s database status information or ask the provider to check the service and resource limits. Restart a database service only when you administer that server, have appropriate authorization, and have confirmed that the operational impact is acceptable; a restart can interrupt active database connections.

3. Verify the four database settings in wp-config.php

Use SFTP or the hosting file manager to open wp-config.php. Compare these values with the current database details in the hosting panel or migration records:

  • DB_NAME — the database WordPress should use
  • DB_USER — the database username
  • DB_PASSWORD — the current password for that user
  • DB_HOST — the database server address or host setting

Check for a stale database name, an outdated password, an incorrect host, or accidental whitespace and quoting changes. Do not assume the previous values remain valid after a migration, hosting move, database restore, or password reset.

4. Test the same connection outside WordPress

Use phpMyAdmin or the MySQL command line with the exact database name, username, password, and host from wp-config.php. This test should use the same environment and credentials that WordPress uses.

  • If the direct connection fails, investigate the credentials, database host, server availability, or network access before changing WordPress files.
  • If the direct connection succeeds, the basic server and credential path works; continue by checking database-user assignment, privileges, and table health.

Never post the password or the complete wp-config.php file when requesting assistance.

5. Confirm database-user access and privileges

In the hosting panel’s database-user section, verify that the user from wp-config.php is assigned to the correct WordPress database and has permission to read and modify its tables. This check is particularly important after restoring a database under a new account or creating a replacement user.

If you administer MySQL directly, an authorized administrator can inspect the account’s grants with SHOW GRANTS. Correct the user-to-database assignment or privileges only after confirming the intended database and account. Then repeat the direct connection test and reload the site.

6. Check for table problems only after the connection works

If the database server is available, the exact credentials work in a direct test, and the user has access, inspect the WordPress tables in phpMyAdmin or through an authorized database tool. CHECK TABLE can report table problems.

Create or verify a current database backup before attempting any repair. REPAIR TABLE is mainly relevant to supported MyISAM tables and is not a universal repair method. Do not run repair commands repeatedly when checks report no corruption; return to the host, configuration, privileges, and server logs for further diagnosis.

7. Verify the complete site after the fix

Load several public pages and /wp-admin/. If both work, clear only relevant caching layers if stale output remains. If either area still fails, capture the exact current message and review the server or hosting logs rather than assuming the original connection problem is unchanged.

Prevention & how to verify the fix

  • Store current database name, user, host, and password details in a protected password manager or equivalent secure record.
  • After every migration or hosting change, test both the public site and /wp-admin/ before completing the move.
  • Maintain regular database backups and periodically confirm that a restore is possible.
  • Record which database user is assigned to each WordPress database so a restore or user replacement does not silently remove access.
  • Review hosting resource alerts and database-service events when available, particularly after unexpected restarts or recurring connection failures.
  • Limit access to wp-config.php and avoid sharing its contents or credentials in support requests.

When to get outside help

Contact your hosting provider when the database service is unavailable, repeatedly stops, exceeds a hosting resource limit, or runs on infrastructure you cannot inspect. Escalate when direct credentials fail despite matching the hosting panel, when the required DB_HOST value is provider-specific, or when table checks report corruption and you do not have a verified backup.

Provide the approximate start time, whether /wp-admin/ also fails, the database-service status, and whether a direct connection test succeeded. Share relevant error details, but never send passwords or an unredacted wp-config.php file.

Run a website check

Frequently asked questions

What does “Error Establishing a Database Connection” mean in WordPress?

It means WordPress could not connect to its configured MySQL or MariaDB database. Start by checking database-server availability, the four connection settings in wp-config.php, and the configured user’s access to the database.

Which wp-config.php settings should I check?

Check DB_NAME, DB_USER, DB_PASSWORD, and DB_HOST. Compare each value with the current database details from your hosting provider, especially after a migration, password change, restore, or hosting move.

How can I tell whether the problem is WordPress or the database server?

Try the same database name, username, password, and host through phpMyAdmin or the MySQL command line. If that direct connection fails, the underlying issue is likely the server, credentials, host, network access, or permissions rather than WordPress page rendering.

Can a database user exist but still cause this error?

Yes. The user can exist without being assigned to the WordPress database or without having the required privileges. Check the user-to-database assignment in the hosting panel or have an authorized administrator inspect its grants with SHOW GRANTS.

Should I repair WordPress database tables immediately?

No. First confirm that the database server is running, the credentials work, and the user has access. If those checks pass, create or verify a current backup and use CHECK TABLE; use REPAIR TABLE only when the reported table type and repair situation support it.

Why did this error appear after a WordPress migration?

The migration may have left wp-config.php pointing to the old database name, user, password, or host. The restored database user may also lack access to the new database. Compare every connection value and verify the user assignment after the move.

Further documentation

For authoritative procedures, consult the official WordPress documentation for wp-config.php database settings and database repair, the MySQL or MariaDB documentation for connection testing and grants, and your hosting provider’s documentation for database host values, service status, and user-to-database permissions. Use the documentation that matches the database engine and hosting environment in use.