
A WordPress error establishing a database connection means your site’s files loaded but could not reach the MySQL or MariaDB database that stores your content. The usual causes are wrong credentials in wp-config.php, a database server that is down or overloaded, or corrupt tables. Fix it in order: confirm the scope, check credentials, check the server, then repair or restore.
Check the Scope Before You Change Anything
Before editing a single file, find out how far this database connection error actually reaches. Open your homepage, one blog post, a key service page, wp-admin, and wp-login.php in separate tabs. If every page shows the same blank page or white screen with the error message, WordPress cannot reach the database at all and the cause sits at the credentials or server level. If wp-admin loads but the public site does not (or the reverse), the problem is narrower, often a caching layer or a single corrupted table, and you can skip straight to the repair step below.
It’s worth ruling out the obvious first: a recent plugin or theme update, a hosting account change, or a WordPress website migration you or your web hosting provider ran in the last day or two. Most database connection issues on an otherwise healthy WordPress installation trace back to something that changed right before the error appeared, not a random failure out of nowhere.
This quick check also tells you whether other sites on the same hosting account are affected. If they are, the server itself is the likely culprit, not your WordPress installation specifically. Knowing the scope up front saves you from changing database credentials that were never wrong in the first place.
What Causes an Error Establishing a Database Connection in WordPress
Most cases trace back to one of four things. Wrong database credentials in wp-config.php is the most common: a hosting migration, a password reset, or a manual edit that introduced a typo in DB_NAME, DB_USER, DB_PASSWORD, or DB_HOST. A downed or overloaded server is next: shared hosting environments cap simultaneous connections, and a traffic spike or a runaway plugin query can exhaust that limit until the database refuses new connections. Corrupt database tables, often from an interrupted update or an abrupt server restart, can also block the connection even when credentials and server status are both fine. Finally, a failed migration or a table-prefix mismatch (your configuration file still points at $table_prefix = ‘wp_’ but the imported database uses a different prefix) produces the exact same error message. In every case the underlying issue is database access, not a broken WordPress installation: the files that make up your site are intact, WordPress simply cannot reach the data behind them.
If you searched for wordpress error establishing a database connection because your site just went down, start with the scope check above, then work through credentials, server status, and table integrity in that order. The WordPress.org common errors documentation covers this error alongside the other white-screen failures it’s often confused with.
The PHP MySQL Extension Error Variant
A closely related but different message is: “your php installation appears to be missing the mysql extension which is required by wordpress.” This is not the same problem as a wrong password or a downed server. It means the PHP runtime on your hosting account does not have the mysqli extension enabled, so WordPress cannot even attempt a database connection, regardless of how correct your configuration file’s credentials are.
You cannot fix this from inside WordPress. It’s a server-side PHP configuration issue, so the fix is to ask your host to enable the mysqli extension for your PHP version, or to switch your account to a PHP version that already has it enabled (most current hosts enable it by default, so this usually shows up after a PHP downgrade or a move to a stripped-down custom PHP build). The PHP manual’s mysqli reference documents what the extension provides and how a host would verify it’s active.
Step 1: Verify Database Credentials in wp-config.php
Connect to your site with an FTP client, SFTP, or your host’s file manager and open wp-config.php (sometimes called the wp-config file) in the WordPress root directory. Compare four values against what your host’s control panel shows for the actual database: DB_NAME, DB_USER, DB_PASSWORD, and DB_HOST. A single typo in the username and password, an incorrect database name, or a hostname that should read localhost but reads something else, is enough to trigger the error.
If you recently changed your database password in your host’s dashboard, that file needs the same update, WordPress will not detect the change on its own. Save the file, then reload the site once. If the credentials were the issue, the error clears immediately.
Step 2: Confirm the Server Isn’t Down
If the credentials check out, the next suspect is the server itself. Log in to your hosting provider’s dashboard or cPanel and look for a database status indicator, resource usage graphs, or a maintenance notice. Shared hosting plans often cap the number of simultaneous connections; if you’re near a traffic spike, that limit can be the entire story.
On managed WordPress hosting, ask your host to confirm the database service is up and check its error logs. On a VPS or dedicated server you manage yourself, you can restart the MySQL service directly and then read its error log for the specific reason it stopped accepting connections. Either way, confirm the server is running again before you touch anything else: a repair or restore attempted while the database is still down will simply fail and cost you extra time.
Step 3: Repair Corrupt Database Tables
When scope and server status both look fine, corrupt tables are next. Add define( 'WP_ALLOW_REPAIR', true ); to wp-config.php, then visit /wp-admin/maint/repair.php in your browser. WordPress will scan and repair the affected tables. Remove that line again once you’re done, leaving it in place is a minor security exposure since the repair page has no login requirement while it’s enabled.
You can also repair tables directly from phpMyAdmin: select the database, select the flagged tables, and use the built-in “Repair table” action. This is useful when the WordPress repair screen itself won’t load because the connection is too unstable to reach it.
Step 4: Test the Connection and Check User Permissions
Once credentials, server status, and tables have all been checked, confirm the database user actually has permission to read and write the WordPress database, not just connect to the database generally. A user created with connection rights but no privileges on the specific database name will still trigger a connection error that looks identical to a credentials mistake. Grant the correct privileges (or recreate the user against the right database) from cPanel or phpMyAdmin, then reload the site to confirm the fix held.
Restore From a Backup When It’s the Safest Option
If configuration and table repair cannot bring the site back safely, particularly after a failed migration or a corrupted import, bringing back a clean copy is the more reliable path. Restore to a staging environment first when your host offers one, so you can confirm the site loads correctly before touching production. Protect any orders, form submissions, or content created since the last snapshot by exporting what you can from the live database before you overwrite it.
If you don’t have a recent backup of your own, ask your hosting provider: most hosts keep server-side snapshots you can request even when your own routine has gaps.
Can Plugins or Themes Cause This Error?
Rarely in a direct way, but yes under load. A plugin that runs heavy or unoptimized database queries can push the server past its connection limit until the database starts rejecting new connections, producing the same database connection error as a genuine outage. If the error only shows up during traffic spikes or after installing a specific plugin, treat it as a resource problem: disable the plugin (via FTP if wp-admin is unreachable, by renaming its folder) and see if the error clears.
How to Prevent This Error in the Future
A few habits keep this error from becoming a recurring emergency. Keep tested, off-server backups on a regular schedule so a bad migration or corrupted table is never a crisis. Update your database credentials the moment they change, don’t wait for the error to force the issue. Add server-level or plugin caching to reduce direct database load on high-traffic pages, and right-size your hosting plan so a normal traffic spike never exhausts your connection limit. If your host offers database load monitoring, turn it on: a warning before the server maxes out is far easier to act on than a site that’s already down, and it gets you back online faster if the error ever returns.
When to Contact Your Hosting Provider
Escalate to your host once your database credentials are confirmed correct, the server appears down or unresponsive from your end, more than one site on the account is affected, or you can’t restart the database yourself on managed hosting. A hosting provider can verify the database service directly and recover from server-side snapshots you may not have access to. If you’d rather not troubleshoot this alone, GEENXT’s WordPress support team handles database connection recovery as part of ongoing maintenance, and our WordPress emergency fixes service covers same-day triage for exactly this kind of outage.
FAQ
What does error establishing a database connection mean in WordPress?
It means WordPress loaded its files but could not connect to the MySQL or MariaDB database that stores your content. The site looks offline, yet the data is almost always intact. The connection, not the content, is what failed.
What typically triggers this database error in WordPress?
The most common causes are incorrect database credentials, a server that is down or overloaded, and corrupt database tables. A failed migration or a table-prefix mismatch can trigger it too, and so can a missing PHP mysqli extension on the host’s side.
How do I check and fix database credentials in WordPress?
Open wp-config.php in the root directory and compare DB_NAME, DB_USER, DB_PASSWORD, and DB_HOST against the values shown in your host’s control panel. Correct any mismatch, save the file, and reload the site to see if the error clears. A single typo in any one of those four values is enough to trigger it.
How can I repair a corrupted WordPress database?
Add define( ‘WP_ALLOW_REPAIR’, true ) to your configuration file, visit /wp-admin/maint/repair.php, and run the repair, then remove that line once it finishes. You can also repair the affected tables directly from phpMyAdmin if the WordPress repair screen itself won’t load.
How do I check if my database server is down?
If other sites on the same hosting account also show the error, the database is likely down or overloaded. On managed hosting, ask your host to confirm and restart it. On your own server, restart the service and read the error log.
Can plugins or themes cause a database connection error?
Rarely in a direct way. A heavy plugin can overload the server with queries until it refuses new connections, producing the same error under load. If it only appears at peak traffic, treat it as a resource problem and find the query-heavy plugin.
How can I prevent this error in the future?
Keep tested off-server backups, update your database credentials whenever they change, add caching to reduce database load, and right-size your hosting so traffic spikes never exhaust the connection limit. Monitoring database load gives you a warning before the site actually goes down.
When should I contact my hosting provider for this error?
Contact your host when the credentials are confirmed correct, the server appears down, multiple sites on the account are affected, or you cannot restart the database yourself on managed hosting. The provider can verify the service and recover data from server-side snapshots.
For deeper troubleshooting beyond this one error, see our full WordPress troubleshooting guide, our walkthrough on fixing the WordPress critical error, and, if a compromise is a possibility, our incident response steps after a WordPress hack. Once the site is back up, our guide to reducing TTFB on WordPress covers the server load and caching habits that help prevent connection-limit errors like this one from recurring. For debugging beyond what’s covered here, the WordPress.org debugging guide explains how to enable WP_DEBUG logging to capture more detail the next time something breaks.