Skip to content

WordPress fixes, security checks, and performance guides for site owners and builders.

Start with fixes
Fixes

How to Fix the WordPress Error Establishing a Database Connection

Fix the WordPress database connection error by checking database credentials, server availability, and damaged tables without risking your site.

4 min read Last updated Jun 15, 2026

A WordPress database connection error means WordPress cannot read the database containing your posts, settings, and user accounts. First, check whether the error affects the entire site. If it does, verify the database details in wp-config.php; if those details are correct, ask your host whether the database server is available.

Do not reinstall WordPress or create a new database. Either action can complicate recovery without addressing the failed connection.

Check whether the database server is down

Open both your homepage and /wp-admin/.

If every page shows the same connection error, the likely causes are incorrect credentials, an unavailable database server, or a connection limit. Check your hosting control panel for database service incidents and resource-limit warnings.

Sites on shared or managed hosting may not provide direct control over MySQL or MariaDB. Contact the host and ask them to confirm:

  • The database server is running.
  • Your database still exists.
  • The database user has access to it.
  • The account has not exceeded database connection or resource limits.
  • The correct database hostname for your account has not changed.

A temporary outage may resolve once the host restores the database service. Editing WordPress files will not fix that kind of failure.

Verify the settings in wp-config.php

WordPress reads its database name, username, password, and server address from wp-config.php. These values commonly become outdated after a migration, hosting change, password reset, or database restoration.

Before editing the file, download a backup copy. Then open wp-config.php in the WordPress installation directory and locate these definitions:

define( 'DB_NAME', 'database_name' );
define( 'DB_USER', 'database_username' );
define( 'DB_PASSWORD', 'database_password' );
define( 'DB_HOST', 'localhost' );

Compare each value with the database information shown by your hosting provider:

  • DB_NAME must identify the existing WordPress database.
  • DB_USER must be a user assigned to that database.
  • DB_PASSWORD must match the current password for that user.
  • DB_HOST must use the hostname and port required by the host.

Do not assume DB_HOST is always localhost. Some providers use a separate hostname, IP address, socket, or port. The official wp-config.php documentation explains the supported database settings.

If you change a value, upload the file and reload the site. Restore your backup copy if the edit introduces a PHP error or another unexpected result.

If the credentials appear correct, you can reset the database user's password through the hosting panel and enter the new password in DB_PASSWORD. Before doing so, check whether another website, application, staging site, or backup service uses the same database account. Changing a shared account's password will break those connections until their configurations are updated.

Keep the previous password available for rollback before making the change. If the new password causes additional failures, restore the previous password in the hosting panel and restore the matching DB_PASSWORD value in each affected configuration. If the panel cannot restore the old password, update every application that uses the account or ask the host to help recover access.

Make sure the database user remains assigned to the WordPress database with the required privileges.

Repair damaged database tables

Use database repair only when the database server is reachable and WordPress indicates that one or more tables need repair. It will not correct an invalid password or restore an unavailable server.

Create a database backup first. Then add this line above the comment that tells you to stop editing wp-config.php:

define( 'WP_ALLOW_REPAIR', true );

Visit:

https://example.com/wp-admin/maint/repair.php

Choose Repair Database. Use Repair and Optimize Database only when optimization is also necessary, because it can take longer on a large site.

The repair page does not require an authenticated WordPress session while enabled. Remove the WP_ALLOW_REPAIR line immediately after finishing, even if the repair fails.

If the repair page cannot connect to the database, return to the credential and hosting checks. If it reports tables that cannot be repaired, stop making changes and restore a known-good database backup or ask the host to inspect the damaged tables.

Check for a compromised configuration

Unexpected database credentials can also result from an unauthorized file change. Compare wp-config.php with a trusted backup and check your hosting account for unfamiliar database users or recent file modifications.

Do not simply restore the connection and ignore unexplained changes. Reset hosting, database, WordPress administrator, SFTP, and SSH credentials as applicable, then review the site for additional compromise.

WordPress lists incorrect configuration, hosting problems, and compromised sites among the possible causes in its guide to common WordPress errors.

Give your host useful details

Escalate the problem when the credentials match the hosting panel but the site still cannot connect, the error returns intermittently, or database repair reports unrecoverable tables.

Send the host:

  • The approximate time the error began.
  • Whether it affects both the public site and /wp-admin/.
  • Any recent migration, restore, password, or hosting changes.
  • Confirmation that the database name, user, and hostname match the control panel.
  • The repair error, if one appeared.

Do not send passwords or the complete contents of wp-config.php. Ask the host to check the database service, user privileges, connection limits, server logs, and table health.

Editorial Staff

The BugWP editorial staff publishes practical WordPress guides for fixes, security, performance, hosting, Cloudflare, and plugin/theme recovery.