The WordPress database connection error is one of the most disorienting failures a site owner can encounter. One moment your site is live; the next, every visitor — including you — sees a stark white page reading “Error Establishing a Database Connection.” No admin panel, no front end, no nothing. I dealt with this exact WordPress database connection error on a client’s WooCommerce store at the worst possible time — hours before a sale campaign went live — and what I learned from that experience is that the fix is almost always systematic and almost never involves data loss. This guide covers every cause and every proven fix for the WordPress database connection error, in the order that resolves it fastest. We go deeper on the whole subject in our WordPress Errors Complete Guide.
What the WordPress Database Connection Error Actually Means
WordPress stores everything — posts, pages, settings, user accounts, plugin configurations — in a MySQL or MariaDB database. When WordPress loads a page, it connects to that database, queries it, and uses the results to build what visitors see. The WordPress database connection error appears when that connection cannot be established. WordPress tries to reach the database, fails, and has nothing left to display.
The error message itself has two flavours. On the front end, visitors see “Error Establishing a Database Connection.” If you try to access the WordPress admin at /wp-admin/, you may see a different variation: “One or more database tables are unavailable” or the generic WordPress database connection error message. Both point to the same underlying problem — WordPress cannot talk to the database.
There are four main reasons the WordPress database connection error appears, and knowing which one you are dealing with determines which fix to reach for first. Incorrect database credentials in wp-config.php are the most common cause by a wide margin. A downed or overloaded database server is the second. Database table corruption is the third. And finally, exhausted database connection limits on shared hosting can produce the WordPress database connection error for some or all visitors when traffic spikes or a runaway plugin holds connections open. Each of these has a different fix, and working through them in sequence is the fastest path to resolution.
Fix 1 — Verify the Database Credentials in wp-config.php
Start here. Wrong credentials in wp-config.php cause the majority of WordPress database connection error cases, especially after hosting migrations, cPanel account changes, or password resets. The fix takes three minutes when this is the cause.
Access your server via FTP, SFTP, or your hosting provider’s file manager. In the root of your WordPress installation — the same directory as wp-login.php and the wp-content folder — open wp-config.php. Find these four lines:
define( 'DB_NAME', 'your_database_name' ); define( 'DB_USER', 'your_database_username' ); define( 'DB_PASSWORD', 'your_database_password' ); define( 'DB_HOST', 'localhost' );
Now log in to cPanel (or Plesk, or your host’s equivalent) and open MySQL Databases. The database name will typically have a prefix matching your hosting account — something like username_wpdb rather than simply wpdb. Verify that DB_NAME matches exactly. Do the same for DB_USER and DB_PASSWORD. A single mismatched character in any of these three fields triggers the WordPress database connection error every time.
DB_HOST is localhost on most shared and managed hosting. Some providers — particularly those using remote database servers — supply a different hostname. If you recently moved hosts or your host has sent configuration emails, check whether a custom DB_HOST was specified. Once you have corrected any mismatches, save wp-config.php and reload your site. If incorrect credentials were the cause, the WordPress database connection error clears immediately.
Fix 2 — Run the WordPress Database Repair Tool
If your credentials are confirmed correct but the WordPress database connection error persists, database table corruption is the likely culprit. WordPress ships with a built-in repair tool that checks every table and repairs structural damage — but it is disabled by default and must be switched on manually.
Open wp-config.php again and add this line directly above the line that reads “That’s all, stop editing!”:
define( 'WP_ALLOW_REPAIR', true );
Save the file, then navigate to https://yoursite.com/wp-admin/maint/repair.php in your browser. You will see two options: Repair Database and Repair and Optimize Database. Click Repair Database and wait for WordPress to work through your tables. Each table is reported as OK or repaired. This process resolves the form of corruption most likely to produce the WordPress database connection error — damaged table indexes, incomplete rows, and similar low-level structural issues.
As soon as the repair completes, go back to wp-config.php and remove the WP_ALLOW_REPAIR line. Leaving it active is a security exposure — anyone who knows the URL can run database repairs on your site without authentication. After removing the line, reload your site and check whether the WordPress database connection error has cleared.
If the repair tool itself cannot load because the WordPress database connection error is preventing all page loads, take the repair directly into phpMyAdmin. Log in to phpMyAdmin through cPanel, click your WordPress database in the left panel, select all tables using the checkbox at the bottom, and choose “Repair table” from the dropdown. This operates on the database directly, bypassing WordPress entirely, and handles the same corruption that the built-in repair tool addresses.
Fix 3 — Check Whether the Database Server Is Down
A WordPress database connection error caused by a server outage looks identical to one caused by wrong credentials — the same message, the same blank front end. The difference is that no local fix will resolve a server-side problem. If you have confirmed your credentials and run database repairs with no improvement, spend two minutes ruling out a hosting-side issue before going further.
Log in to your hosting control panel and look for a server status indicator or check your host’s status page — most providers maintain a public status URL. Alternatively, contact support directly and ask whether the MySQL server is operational. Managed WordPress hosts like Kinsta, WP Engine, and Cloudways have status dashboards that show real-time database server health. On shared hosting, the MySQL server going down affects every site on that server simultaneously, so a quick search for your host’s name plus “down” in the past hour will often surface reports if there is an active incident causing the WordPress database connection error across multiple customers.
Connection limit exhaustion is a server-side issue that is harder to identify from the outside. On shared hosting plans with low concurrent connection caps, a traffic surge or a plugin that opens database connections without closing them properly can exhaust the limit and produce the WordPress database connection error intermittently — some page loads succeed, others fail. If this is the pattern you are seeing, contact your host and ask about the MySQL max_connections limit for your plan. On VPS or dedicated servers where you have server access, you can check the current connection count directly and raise the limit in my.cnf if needed.
Fix 4 — Deactivate Plugins and Replace Core Files
Plugins that interact with the database — caching plugins, database cleaners, backup tools, advanced query plugins — can occasionally produce the WordPress database connection error by corrupting tables during a failed operation or by exhausting connections during a runaway process. Systematically deactivating plugins is the right approach when other fixes have not resolved the WordPress database connection error.
Because the admin panel is inaccessible during a WordPress database connection error, plugin deactivation must be done via FTP. Connect to your server, navigate to wp-content/plugins/, and rename the folder to plugins_bak. WordPress treats this as all plugins being absent and deactivates everything. Reload your site — if the WordPress database connection error is gone, a plugin is responsible. Rename the folder back to plugins, then rename individual plugin subdirectories one at a time, reloading after each, until the error returns. The last plugin you renamed before the error returned is the problem.
Core file corruption is less common but worth checking. Download a fresh copy of WordPress from wordpress.org, extract it, and upload the wp-admin and wp-includes directories to your server, overwriting the existing versions. Do not touch wp-content or wp-config.php. Replacing core files eliminates file-level corruption that occasionally contributes to the WordPress database connection error on sites that had an incomplete update or a filesystem error.
Preventing the WordPress Database Connection Error
The most effective prevention for the WordPress database connection error is a combination of daily automated backups, routine database maintenance, and a hosting environment with adequate resources. A site with a clean recent backup can recover from the most severe WordPress database connection error — even complete database corruption — in minutes rather than hours.
Automated backups using UpdraftPlus or your host’s native backup system should run daily and store copies offsite — not only on the same server whose database just failed. Database maintenance with a tool like WP-Optimize keeps tables clean and prevents the gradual table bloat that can eventually contribute to corruption errors. Keeping WordPress core, themes, and plugins updated closes the bugs that cause the failed database operations most likely to lead to the WordPress database connection error in the first place.
Choosing a hosting plan with sufficient database resources for your site’s actual traffic level matters more than most site owners realise. A shared hosting plan with tight connection limits that works fine at launch becomes a source of intermittent WordPress database connection errors as traffic grows. Monitoring your site’s database connection count with a plugin like Query Monitor, and upgrading your hosting plan before the limits are hit rather than after the WordPress database connection error starts appearing, is the most reliable prevention available.
Our guide on how to back up a WordPress site properly covers the backup tools and schedules that turn a severe WordPress database connection error from a crisis into a quick restore. Our guide on fixing WordPress database tables missing errors covers the related scenario where specific tables are absent rather than the connection failing entirely. The WordPress support forums maintain active threads on database connection issues with solutions specific to common hosting configurations — worth checking if none of the above resolves your specific error. Our guide on How to Fix WordPress Error Establishing a Redis Connection covers an adjacent issue.






