WordPress

How to fix "database connection error" in WordPress

This error means WordPress can't reach or authenticate with its database, and the four possible causes each have entirely different fixes. Guessing wastes the exact time you don't have while your site is fully down.

V Vinod Kulkarni
1 September 2026 · 8 min read
How to fix "database connection error" in WordPress

How to fix "database connection error" in WordPress

TL;DR: "Error establishing a database connection" means WordPress's PHP code could not successfully connect to the MySQL/MariaDB database it needs to load any content at all, since WordPress stores essentially everything, posts, settings, users, in the database rather than in static files. The four causes, in order of how common they are: incorrect database credentials in wp-config.php (often after a migration or a password change), the database server itself being down or unreachable, a corrupted database or specific table, and the database connection limit being exceeded under high load. Each requires a different, specific fix, and checking which one applies takes only a few minutes.

Why this error takes down the entire site

WordPress stores nearly all of its actual content and configuration, posts, pages, settings, user accounts, comments, in the MySQL or MariaDB database, using the file system primarily for the WordPress core software itself, themes, plugins, and uploaded media files. This architecture means that when the connection to the database fails for any reason, WordPress has no way to load or render any content at all, since almost everything it needs to build a page comes from a database query, which is why this specific error takes down the entire site uniformly (unlike, for example, a plugin conflict that might only affect a specific feature or page) rather than presenting as a partial or intermittent failure.

Step 1: check wp-config.php credentials first

This is the most common cause and the fastest to check, so it should always be the first thing you verify. WordPress's database connection details, database name, username, password, and host, are stored in wp-config.php, in the site's root directory. Access this file via FTP or your hosting file manager and confirm these four values exactly match what your hosting account's actual database credentials are, which you can verify directly through your hosting control panel's database management section.

This specific cause is disproportionately common immediately after a migration (where credentials from the old host were not correctly updated for the new one), after a manual password change to the database user (made directly in the hosting panel without correspondingly updating wp-config.php to match), or after a restored backup that included an outdated wp-config.php referencing the previous environment's credentials rather than the current one.

If any of the four values (database name, username, password, host) do not exactly match your hosting account's actual current database details, correcting them in wp-config.php and saving typically resolves the error immediately, since this confirms the site's configuration was simply pointing at incorrect or outdated connection information rather than reflecting any deeper problem.

Cause 2: the database server itself is down

If credentials in wp-config.php are confirmed correct, but the site is still showing this error, the next possibility is that the database server itself is not currently running or reachable, a hosting infrastructure-level issue rather than a WordPress configuration issue. This can happen due to a server-side outage, the database service crashing or being restarted, or, on resource-constrained hosting, the database process being killed due to memory exhaustion under load.

Checking your hosting provider's status page for any reported outage, or contacting hosting support directly to confirm whether the database service is currently running correctly on their end, is the appropriate next step here, since this cause is outside what you can directly fix yourself if it originates at the infrastructure level rather than in your own site's configuration.

Cause 3: a corrupted database or table

Less common, but a corrupted database table, sometimes resulting from an interrupted operation (a plugin update that failed partway through a database migration step, an improperly interrupted import, or in rare cases underlying disk-level issues on the server), can cause connection or query failures that present with this same generic error message, even though the actual credentials and database server availability are both fine.

If you have access to phpMyAdmin or a similar database management tool through your hosting control panel, checking for and repairing any tables flagged as corrupted or requiring repair (most database management interfaces include a built-in "repair table" function for exactly this situation) can resolve this specific cause directly. If you are not comfortable working directly with database repair tools, this is a reasonable situation to involve your hosting provider's support, particularly if backups are available to restore from as an alternative to manual repair.

Cause 4: connection limit exceeded

Database servers, particularly on shared hosting, typically have a configured maximum number of simultaneous connections allowed, and if this limit is exceeded, whether due to a genuine traffic spike, an inefficient plugin opening far more database connections than necessary, or a broader resource contention issue on shared infrastructure, new connection attempts (including the one your WordPress site needs to load a page) can fail, again presenting with this same generic error message despite correct credentials and a genuinely running database server.

This cause is often intermittent rather than constant, since the error may only appear during actual peak load moments rather than persistently, which is itself a diagnostic clue: if the error comes and goes rather than being constantly present, connection limits or resource contention are a more likely cause than incorrect credentials (which would produce a constant, unchanging failure) or a fully down database server (which would also typically be constant until resolved).

Flowchart showing the correct diagnostic order for a database connection error: check wp-config.php credentials first, then confirm database server is running, then check for corrupted tables, then check for connection limit issues under load

A diagnostic table

Pattern observed Likely cause What to check
Constant error, started right after a migration or password change Incorrect credentials in wp-config.php Compare wp-config.php values against actual hosting database credentials
Constant error, no recent change made Database server down Hosting status page, contact hosting support
Error only on specific pages or intermittently, database otherwise seems to work Corrupted table phpMyAdmin table status, repair function
Intermittent error, worse during high traffic Connection limit exceeded Hosting resource limits, plugin database query behavior

Why this happens especially often after migrations

It is worth calling out specifically since it is such a common trigger: a domain, host, or server migration is the single most common circumstance under which this error appears, because a migration frequently changes database credentials (a new hosting environment issues new credentials different from the old one) without every reference to those credentials, particularly in a restored wp-config.php file carried over unchanged from the old environment, being correspondingly updated. If this error appeared specifically right after a migration, checking wp-config.php against the new environment's actual current database credentials should be treated as the near-certain first cause to investigate, before considering any of the other three possibilities.

FAQs

Will fixing this error lose any of my content?

No, provided the cause is credentials, server availability, or connection limits (Causes 1, 2, and 4), your actual data remains entirely intact in the database throughout; only a genuinely corrupted table (Cause 3) carries any risk to specific data, and even then, a proper repair operation or restoring from backup typically preserves the vast majority of content with minimal or no loss.

How do I find my hosting account's actual current database credentials?

Check your hosting control panel's database management section directly (in cPanel, for example, this is typically under "MySQL Databases" or similar), which shows the current database name and username; the password may need to be reset if you do not have it recorded, which is a normal, safe operation as long as you then correspondingly update wp-config.php with the new password immediately after resetting it.

Can a plugin cause this error?

Indirectly, yes, particularly a plugin that opens an excessive number of database connections or performs an operation that corrupts a table during a failed process; if this error started right after installing or updating a specific plugin, deactivating it (via FTP, since you cannot access wp-admin while this error is present) and checking whether the error persists helps isolate a plugin-specific cause.

Is this the same as a "500 internal server error"?

No, they are distinct, though related in that both can leave a site completely inaccessible; a database connection error is specifically about the database layer, while a 500 error is a broader, more general server-side failure indicator that can have many other causes beyond database connectivity, covered in our dedicated 500 error guide.

Does this error affect my email or only my website?

If email is hosted separately from your database (common, since email typically does not depend on WordPress's own database), email should be unaffected; if you use a WordPress plugin for email functionality that itself depends on the database (less common for core email delivery, more common for logging or queue-management plugins), that specific plugin's functionality could be affected while core email delivery through your actual mail server remains unaffected.

Should I restore from backup immediately if I see this error?

Not necessarily as a first step; checking wp-config.php credentials first (the most common cause, and the fastest and lowest-risk fix) is worth doing before considering a restore, since a credentials fix resolves the issue with zero data loss and no need for a broader restore operation at all.

How urgent is fixing this compared to other WordPress errors?

Very urgent, since this error takes the entire site down completely for every visitor, unlike many other WordPress errors that might affect only a specific page or feature; treat this as a "fix immediately" priority rather than something to investigate at leisure, given the complete site unavailability it causes.

Conclusion

A database connection error means WordPress cannot reach the database it needs for essentially all of its functionality, and the fix depends entirely on which of four possible causes applies: incorrect credentials (most common, especially post-migration), a down database server, a corrupted table, or an exceeded connection limit. Checking wp-config.php credentials against your actual current hosting database details should always be the first step, since it is the most common cause, the fastest to check, and carries zero risk to your data if it turns out not to be the actual cause.

Given that this error takes the entire site offline, working through the diagnostic order above quickly, rather than guessing at a single cause, gets you back online faster than trial-and-error troubleshooting.

HostCloud's hosting support can directly confirm database server status and connection limits within minutes if a credentials check does not resolve the issue, and our managed WordPress plans include daily backups as a safety net for any deeper corruption-related recovery. Plans start at ₹99 a month at https://hostcloud.in.

Related posts