Seeing “Error establishing a database connection” on your WordPress site can feel alarming. The message means WordPress could not connect to the database that stores your posts, pages, settings, and user accounts. It does not automatically mean your content is gone. In many cases, the cause is a temporary hosting problem or an incorrect database setting that can be checked and corrected safely.
Start with the fastest reversible checks. Before editing files, changing passwords, or restarting services, record what you see and make a backup if you can. This guide walks through rapid outage triage, wp-config.php database settings, and hosting health checks—with a clear “what changed” and “how to roll back” note for each fix.
First: Record the Error and Check the Scope
Before making changes, note the time the error began, the exact message, and what you were doing just before it appeared. This scratchpad can help you spot a pattern and will be useful if your hosting provider needs to investigate.
- Time and time zone: Record when you first saw the issue. Exact error: Note whether the message appears on every page, only in the WordPress admin area, or in a different form. Recent changes: Record any plugin or theme updates, password changes, migrations, DNS edits, or hosting changes. Who is affected: Check the site in a private browser window and, if possible, on another network or device.
Also check whether the hosting control panel or status page reports a database outage or planned maintenance. Use a separate device or mobile connection if the control panel is hosted on the same server as your site.
Quick checks that are safe and reversible
Reload the site once, then try the homepage and /wp-admin/. Check the host’s service-status page for a database or server incident. Ask a colleague whether they see the same error, if that is practical. Pause. Avoid repeated password changes, plugin installs, or database repair attempts until you have a backup and a reason to proceed.If the error appeared briefly and then cleared, the database may have been temporarily unavailable. Keep the timestamp and check whether the issue returns before changing configuration. If the outage persists, continue below.
What the Error Means
WordPress uses a database—usually MySQL or MariaDB—to retrieve and save site information. When someone visits a page, WordPress needs to connect to that database using a hostname, database name, username, and password. error establishing database connection If the server cannot be reached, the login details are wrong, or the database service is unavailable, WordPress may display the connection error.
The underlying cause could be a simple typo in wp-config.php, a password change that was not reflected in the site’s settings, a database server problem, or a resource limit. A database connection error is therefore a symptom, not a diagnosis. Avoid assuming that the database has been deleted or corrupted without evidence.
Check the Database Settings in wp-config.php
The wp-config.php file in your WordPress installation contains the main database connection settings. These are often called the DB_NAME, DB_USER, DB_PASSWORD, and DB_HOST values. A mismatch in any of them can cause a WordPress database connection error.
Before you edit anything
- Use your hosting file manager or a secure SFTP connection to locate the site’s WordPress files. Download a copy of wp-config.php to a secure location before editing it. Do not paste database passwords into public support forums, email threads, or screenshots. If you are unsure which WordPress installation is live, stop and confirm the document root before changing files.
Open the file in a plain-text editor and find the database constants. They typically resemble the following example; your actual values will differ:
define( 'DB_NAME', 'database_name' );
define( 'DB_USER', 'database_user' ); define( 'DB_PASSWORD', 'database_password' ); define( 'DB_HOST', 'localhost' );Compare each value with the database information shown in your hosting control panel. Do not assume localhost is correct: many hosts use a specific database hostname, and some use a hostname plus a port or socket detail. Use the value supplied for your hosting account rather than copying an example from another site.
Setting What to verify Common source of mismatch DB_NAME The exact database name assigned to this WordPress site Different database selected during migration or account setup DB_USER The database user associated with the site Username changed, mistyped, or not assigned to the database DB_PASSWORD The current password for that database user Password changed without updating the WordPress configuration DB_HOST The database host specified by your provider Incorrect hostname or an outdated server addressFix: Correct a confirmed credential mismatch
What changed: Only the incorrect database value in wp-config.php, updated to match the hosting account’s verified database details.
How to roll back: Restore the original file you downloaded before editing. If you cannot access the site afterward, restore that copy using the same file manager or SFTP method.

Change only a value you have verified. Do not guess passwords or cycle through different hostnames. If credentials are unclear, use the host’s control panel to confirm them or request the exact values from support using the script near the end of this article.
Check Hosting and Database Server Health
A correct wp-config.php cannot connect if the database server is down, unreachable, or overloaded. A hosting incident may affect one account, a group of servers, or an entire region. A site can also fail to connect if it has reached a limit on database connections or if the server is short on memory or disk space.
Look for signs of a hosting-side problem
- The site worked normally and failed suddenly, with no recent configuration change. The hosting control panel reports maintenance, high load, or a MySQL/MariaDB incident. Other sites on the same hosting account are also unavailable or unusually slow. The host’s database tools fail to load or report that the database server cannot be reached. The outage comes and goes, which can indicate an intermittent server or resource issue.
If you have access to the hosting panel, check its service status, resource-usage graphs, and error logs. Look for timestamps that match your scratchpad. Do not restart a database service yourself unless you manage that server and understand the impact; a restart may interrupt other sites or services.
Fix: Wait out a confirmed provider incident
What changed: Nothing on your WordPress site. You confirmed an active hosting-side incident and avoided altering working settings while the provider investigates.
How to roll back: No rollback is needed because no site configuration was changed. Retest the site after the provider reports recovery.
If there is no reported outage but the error persists, contact the provider with the recorded details. Ask them to check whether the database service is reachable from your account, whether the database user is allowed to connect, and whether your account has hit connection, storage, or resource limits.
Check for Recent Changes
Think through what happened shortly before the error began. A migration can leave the site pointing to the old database host. A password rotation can make the DB_PASSWORD value outdated. A DNS change can direct visitors to a different server than the one you inspected. A plugin update is less likely to cause a direct credential mismatch, but it may coincide with other changes or expose an existing server problem.

Use your scratchpad to connect the time of the outage with update logs, hosting notices, backups, or maintenance work. Change one thing at a time. If you make several changes together, it becomes much harder to identify the cause and safely undo the fix.
Should You Repair the Database?
Not as your first step. A connection error does not prove that the database is damaged. First confirm that the database server is available and that the connection values are correct. If you have evidence of corruption—for example, a database tool reports damaged tables—take a full backup before attempting a repair.
WordPress includes a database repair option that some site owners enable temporarily with a setting in wp-config.php. This is not a substitute for a backup or for checking server health, and it should not be left enabled unnecessarily. If you are not familiar with database repair, ask your host or a qualified WordPress technician to review the issue before proceeding.
Fix: Repair only after a backup and confirmed database issue
What changed: Database repair was run only after a verified database problem was found and a backup was made.
How to roll back: Restoring a database backup is the usual way to undo a repair that caused a problem. Confirm that the backup is complete and restorable before starting; a repair itself may not have a simple undo button.
When to Ask Your Host for Help
For a hosting-side issue, specific questions are more useful than a general request to “fix WordPress.” Send a concise report with your site address, the first observed time and time zone, the exact error, recent changes, and any relevant log entries. Never send your database password in a standard support ticket unless the provider has a secure, approved method for sharing credentials—and usually it should not be necessary.
You can use this script:
“My WordPress site at [domain] has shown ‘Error establishing a database connection’ since [time and time zone]. The issue affects [the whole site / the admin area / certain pages]. I have not changed the database settings, or the recent change was [describe it]. Please check whether the database service is healthy and reachable from my hosting account, confirm the correct database hostname and account-to-database permissions, and check for connection, disk, or resource limits. Please also review server logs around [timestamp].”
Rapid Triage Checklist
Record the exact error and time, then check whether the site, admin area, or both are affected. Check the hosting status page and account resource indicators. Back up wp-config.php before editing it. Compare all four wp-config.php database settings with verified hosting details. Review recent password, migration, DNS, or hosting changes. Make one confirmed change at a time and document how to reverse it. Ask the host to investigate server reachability and logs if settings are correct or the cause is unclear.Prevent the Next WordPress Database Connection Error
Keep a recent, tested backup of both your site files and database. Store database credentials securely, and update the WordPress configuration whenever those credentials are deliberately changed. Before a migration or hosting switch, confirm the destination database name, user, password, and hostname, then test the site before changing traffic. Keep a simple change log with timestamps; during an outage, knowing what changed—and when—can save valuable time.
The safest response to a wordpress database connection error is methodical: check the reversible basics first, verify the wp-config.php db settings against authoritative hosting details, and investigate server health before attempting repairs. That approach helps distinguish a local configuration mistake from a genuine mysql connection issue without risking unnecessary changes to your site.