Home / WordPress Guides / Troubleshooting / How to Fix the Error Establishing a Database Connection in WordPress

How to Fix the Error Establishing a Database Connection in WordPress

TABLE OF CONTENTS

Free WordPress Site Review

Is your WordPress setup ready for what 2026 demands?

TL;DR

The “Error establishing a database connection” message means WordPress cannot connect to the database it needs to load your website. Common causes include incorrect database credentials, an unavailable database server, or database-related problems.

To troubleshoot it:

    • Check wp-config.php: Verify the database name, username, password, and host against your hosting configuration.
    • Check database availability: If the credentials are correct, investigate whether your database server is running and accepting connections.
    • Repair only when necessary: Database repair may help with damaged tables, but it won’t fix incorrect credentials or an unavailable server.

Before editing configuration files or attempting repairs, make sure you have a recent backup. If the database server is inaccessible, your hosting provider may need to investigate.

When WordPress displays “Error establishing a database connection,” your website may become inaccessible to visitors and administrators. The error appears when WordPress cannot establish the database connection required to retrieve content, settings, and other stored information.

The cause isn’t always a damaged database. Incorrect connection details in wp-config.php, database server downtime, or hosting resource limits can produce the same message.
This guide explains how to identify the likely cause, check your database configuration, and determine which repairs are appropriate. We’ll also cover when the problem requires assistance from your hosting provider or a WordPress developer.

What Causes the WordPress Database Connection Error?

WordPress relies on a MySQL or MariaDB database to retrieve posts, settings, user information, and other site data. When the database connection fails, WordPress cannot load that information.

The error message doesn’t identify the exact cause. The most useful starting point is to check when the error appeared and what changed immediately before it.

What you’re experiencing What to investigate first
The error appeared after a website migration Check the database name, username, password,
and host in wp-config.php against the new
hosting environment.
The website stopped working without any
recent changes
Check whether the database server is available
and whether your hosting provider has
reported an outage.
The error appears intermittently, then
disappears
Investigate temporary connection failures,
database connection limits, and server
resource usage.
The error started after editing wp-config.php Compare the database configuration with
the last known working version.
You suspect damaged database tables Look for supporting database errors before
attempting repairs. A connection error alone
doesn’t confirm corruption.
These patterns help narrow down the investigation, but they aren’t definitive diagnoses. For example, a website that fails immediately after migration could have both incorrect connection settings and a database server that isn’t accepting connections.

Before You Change Database Settings

A database connection error doesn’t necessarily mean your data is lost. Before editing WordPress configuration files or attempting repairs, make sure you can recover the existing website if something goes wrong.

Three precautions matter:

  • Preserve the current database. Check whether your hosting account has a recent, usable backup. If the database is accessible, create a fresh export before attempting repairs. Avoid restoring an older backup without considering any newer content, orders, or user data it could overwrite.
  • Locate your hosting configuration. You’ll need access to your hosting control panel or server files to inspect wp-config.php. Database names, users, and server addresses may differ between hosting environments.
  • Keep credentials private. Never publish your database password or share an unredacted copy of wp-config.php. The file may contain authentication keys and other sensitive settings.
If your hosting provider reports a database outage, investigate that first. Changing credentials won’t restore a database service that is unavailable.

1. Check Your WordPress Database Credentials

WordPress stores its database connection settings in wp-config.php. If any of these values are incorrect, WordPress may be unable to connect to the database, even when the database server is working normally.
Open your hosting File Manager or connect through SFTP and locate wp-config.php, usually in the WordPress installation directory or one level above it.
Find these four settings:
define( 'DB_NAME', 'your_database_name' );
define( 'DB_USER', 'your_database_user' );
define( 'DB_PASSWORD', 'your_database_password' );
define( 'DB_HOST', 'localhost' );

What each setting controls:

  • DB_NAME: The database WordPress should connect to.
  • DB_USER: The MySQL or MariaDB user assigned to that database.
  • DB_PASSWORD: The password associated with that database user.
  • DB_HOST: The database server address. Depending on your hosting provider, this may be localhost, a specific hostname, or an address with a custom port.

Verify the settings against your hosting account

If your host uses cPanel, open MySQL Databases (sometimes called Manage My Databases).

Error Establishing a Database Connection: cPanel Database
Check that the database exists, confirm the assigned database user, and verify that the user has the necessary permissions.
Compare these details with the values in wp-config.php. Database names and usernames may include a hosting-account prefix, so make sure you’re comparing the complete values.

Don’t reset the database password just to test the connection. Hosting dashboards generally don’t display existing database passwords. If you have a securely stored working credential, use it for verification. Otherwise, coordinate any password reset with your hosting provider and update wp-config.php accordingly.

If the values match and the database user has the required access, move on to checking database server availability rather than repeatedly changing credentials.

2. Check Whether Your Database Server Is Running

If your database credentials are correct but WordPress still displays the connection error, the next step is to determine whether the MySQL or MariaDB server is available.
A database server can become temporarily unavailable because of a service interruption, exhausted resources, or connection limits. These problems can occur even when nothing has changed in your WordPress installation.

Check database access through your hosting panel

If your hosting account includes phpMyAdmin, open it and check whether you can access the database used by WordPress.

If the expected database is missing, confirm that you’re connected to the correct hosting account or database server before making changes.
Being able to open a database in phpMyAdmin is useful, but it doesn’t prove that WordPress can connect using the credentials and host specified in wp-config.php. The two connections may use different authentication settings or connection paths.

Check for server interruptions and connection limits

If the database is accessible but the error continues, review your hosting provider’s service status and available server logs.
For intermittent errors, ask your hosting provider to check whether:
  • The MySQL or MariaDB service restarted or became unavailable when the error appeared.
  • Database connection limits were reached.
  • Server memory, CPU, or other resource limits affected database availability.
Record when the error occurs and whether it affects the entire website or disappears after a refresh. These details can help distinguish a temporary server problem from a persistent configuration issue.

Avoid restarting the database service without confirming the cause. On shared hosting, this is normally managed by the provider. On a VPS or dedicated server, restarting MySQL or MariaDB can interrupt other applications using the same database service.

3. Repair the WordPress Database – Only If Tables Are Damaged

A database connection error doesn’t automatically mean your WordPress database is corrupted. If the database server is unavailable or your connection credentials are incorrect, running a repair won’t resolve the problem.
Database repair becomes relevant when server logs, database checks, or your hosting provider identify damaged tables.

Use WordPress’s built-in database repair tool

WordPress includes a database repair utility, but it should only be enabled when needed.
Before proceeding, make sure you have a usable database backup.

1. Open wp-config.php through your hosting File Manager or SFTP.

2. Add the following line before /* That's all, stop editing! Happy publishing. */, or the equivalent end-of-configuration comment: define( ‘WP_ALLOW_REPAIR’, true );

3. Save the file and visit https://yourdomain.com/wp-admin/maint/repair.php, replacing yourdomain.com with your website’s domain.

4. Select Repair Database and review the results.

Error Establishing a Database Connection: Repair Database page

Remove the WP_ALLOW_REPAIR line immediately after the repair attempt, even if the problem persists. While enabled, the repair page can be accessed without logging into WordPress.

What if the database repair fails?

A failed repair may indicate a problem that requires database-level investigation.

Check the reported table errors and contact your hosting provider before attempting further repairs. Some database storage engines and types of corruption require different recovery methods.

Don’t reset or replace your database unless you’ve confirmed the problem and understand which data would be affected. Restoring an older backup may overwrite newer posts, customer records, or WooCommerce orders.
If the database connection itself still fails, return to the credential and server checks rather than repeating the repair process.

4. Check for Missing or Corrupted WordPress Files

Damaged WordPress core files are not a typical cause of database connection errors. However, file integrity is worth checking if the problem appeared after an interrupted WordPress update, a failed deployment, or manual changes to core files.
Before replacing anything, look for evidence that a file is missing or has been modified unexpectedly.

Verify WordPress core files

If your hosting environment supports WP-CLI, a developer or server administrator can run:
wp core verify-checksums
This compares installed WordPress core files with the official checksums for the corresponding WordPress version.

A failed checksum check identifies files that differ from the expected version, but it doesn’t automatically confirm that those differences caused the database connection error.

Replace files only when necessary

If core files are confirmed to be damaged or missing, they can be restored using the appropriate official WordPress package.
Preserve your existing wp-config.php and wp-content directory, including themes, plugins, and uploads. Take a complete backup before replacing files, and follow the official WordPress manual update procedure.
If the core files pass verification, return to the database configuration and server diagnostics. Reinstalling WordPress won’t fix an unavailable database server or incorrect connection credentials

5. Investigate Recent Changes and Persistent Database Errors

If the connection settings appear correct and the database server is available, look at when the error started. A website that fails immediately after migration needs a different investigation from one that stops working for a few minutes and then recovers.

Database connection error after a WordPress migration

Moving a WordPress site to another hosting environment can change the database hostname, database name, or user permissions.
Confirm that the database was imported into the intended server and that the credentials in wp-config.php refer to that database. Also check whether the database server allows connections from the server running WordPress, particularly when the database is hosted separately.
Don’t assume that updating the website URL will resolve a database connection failure. WordPress must establish a working database connection before it can retrieve most site settings.

Intermittent WordPress database connection errors

If the error disappears after refreshing the page but returns later, repeatedly changing database credentials is unlikely to help.
Instead, record when the interruptions occur and compare those times with server activity. Ask your hosting provider to check for database service restarts, exhausted connection limits, and resource spikes.
For example, a database that reaches its connection limit may temporarily reject additional requests even though its credentials are correct.
A recurring connection error needs evidence from the affected period. Without server logs or monitoring data, an apparent recovery doesn’t confirm that the underlying issue has been resolved.

What to Send Your Hosting Provider

If your database credentials appear correct but WordPress still cannot connect, your hosting provider can check server-level information that may not be available through your hosting dashboard.
Include these details in your support request:
  • Affected website: The domain and whether the error affects the entire site or only occurs intermittently.
  • When it started: The approximate time, time zone, and whether the error followed a migration, update, or hosting change.
  • Checks already completed: Whether the database exists, the database user has the required permissions, and phpMyAdmin can access it.
  • Relevant error messages: Any database or PHP errors you’ve found, with sensitive information removed.

Ask your provider to check the MySQL/MariaDB service status, database connection limits, server resource usage, and relevant error logs around the time of the failure.

Don’t send database passwords or an unredacted wp-config.php file in a support ticket. Your hosting provider should be able to investigate the service without requiring you to disclose those credentials.

When to Get Professional WordPress Help

If your database credentials are correct and your hosting provider confirms that MySQL or MariaDB is running, the problem may require a closer investigation of your WordPress installation.
Technical assistance is worth considering when:
  • The error persists after migration. The database exists, but WordPress still cannot connect using the configured credentials.
  • Database permissions or configuration need further investigation. The issue involves database user privileges, custom server settings, or application-level connection errors.
  • A repair attempt fails. Database checks reveal damaged tables or errors that cannot be resolved safely through the standard repair tool.
  • The website contains important live data. Further changes could affect recent orders, user accounts, or other information that has not been backed up.
If the database server itself is unavailable, contact your hosting provider first. A WordPress developer cannot directly resolve a hosting infrastructure failure without the necessary server access.

For WordPress-side issues, Kiwistic’s One-Time Fix service provides a way to request technical assistance without committing to a monthly maintenance plan. Describe the error, when it started, and which checks you’ve already completed so the problem can be assessed before work begins.

How to Reduce the Risk of Recurring Database Errors

Not every database connection failure is preventable. Hosting outages, server resource limits, and temporary MySQL or MariaDB interruptions can occur even when WordPress is configured correctly.
However, a few precautions can reduce avoidable problems and make recovery easier:
  • Keep recoverable database backups. Check that backups are running and periodically verify that they can be restored.
  • Document configuration changes. Record database hostname, user, or server changes during migrations and hosting updates. Store sensitive credentials securely, not in public documents.
  • Monitor recurring interruptions. If connection errors appear during traffic spikes or scheduled tasks, investigate the corresponding server logs and resource usage.
  • Check the site after migrations. Confirm that WordPress connects to the intended database before considering the migration complete.
These precautions won’t eliminate database outages, but they can help distinguish configuration mistakes from infrastructure problems and reduce recovery risks.

Conclusion

The “Error establishing a database connection” message doesn’t reveal whether the problem is in WordPress configuration, database access, or the hosting environment.
Checking the connection details in wp-config.php and confirming database server availability should come before attempting repairs or replacing WordPress files.

If the problem persists, use the evidence you’ve collected to determine whether your hosting provider or a WordPress developer needs to investigate further. Avoid repeated configuration changes without identifying the cause, particularly on websites with active customer or transaction data.

FAQ

Does a database connection error mean my WordPress data is lost?

Not necessarily. The error means WordPress cannot establish the connection needed to access its database. Your posts, pages, users, and settings may still be intact.

Before attempting to restore or replace the database, check whether it exists and whether your hosting provider can access it.

Can I fix the database connection error without WordPress admin access?

Yes, depending on the cause. Database connection settings can be inspected through your hosting File Manager or SFTP, while database availability can be checked using hosting tools such as phpMyAdmin.

Some problems require assistance from your hosting provider, particularly when the database server is unavailable or access is restricted.

Will reinstalling WordPress fix a database connection error?

Usually not if the problem involves incorrect database credentials or an unavailable database server.

Reinstalling WordPress core files may be appropriate when file corruption has been confirmed, but it won’t automatically repair a damaged database or restore a failed server connection. Identify the cause before replacing files.

Ognjen Velickovic

WordPress Developer & Product Manager at Kiwistic. I build and maintain WordPress sites for small businesses and troubleshoot everything from login lockouts to security issues. These guides come from real experience, so you don't have to figure it out alone.

You May Also Like…