Physical Address
304 North Cardinal St.
Dorchester Center, MA 02124
Physical Address
304 North Cardinal St.
Dorchester Center, MA 02124
Step-by-step guide to fix the 'Error Establishing a Database Connection' in WordPress. Check credentials, repair database, and prevent it from happening again.
This page may contain affiliate links. If you purchase through one of these links, I may earn a small commission at no extra cost to you. I only recommend products and services I have personally used or thoroughly evaluated.
Few things make your stomach drop quite like loading your WordPress site and seeing a stark white page that reads: “Error Establishing a Database Connection.” No dashboard, no content, no nothing. Just that ominous message staring back at you.
I have dealt with this error more times than I would like to admit, across my own sites and while helping others troubleshoot theirs. The good news is that in almost every case, the fix is straightforward once you know where to look. In this guide, I will walk you through the most common causes and solutions, ordered from the most likely culprit to the least. By the end, you should be able to get your site back online — or at least understand exactly what went wrong.
WordPress is a dynamic content management system. Every page, post, comment, setting, and plugin configuration lives in a MySQL (or MariaDB) database. When someone visits your site, WordPress connects to that database, retrieves the relevant data, and assembles the page on the fly.
The “Error Establishing a Database Connection” message appears when WordPress attempts to connect to the database server and fails. The connection never completes, so WordPress has no data to work with and cannot render anything at all.
There are a handful of reasons this can happen, but they generally boil down to one of the following: incorrect credentials, the database server being unreachable, corrupted database tables, or resource limits being hit on your hosting account. Let us work through each one.
This is the single most common cause, especially if the error appeared right after a migration, a hosting change, or someone editing the configuration file. WordPress stores its database connection details in a file called wp-config.php, located in the root directory of your WordPress installation.
Connect to your server via SFTP or your hosting file manager and open wp-config.php. Look for the following four lines:
define( 'DB_NAME', 'your_database_name' );
define( 'DB_USER', 'your_database_username' );
define( 'DB_PASSWORD', 'your_database_password' );
define( 'DB_HOST', 'localhost' );Each one of these values must exactly match the credentials set up in your hosting control panel. Here is what to verify:
username_).localhost on most shared hosting setups, but not always. Some hosts use a specific hostname like mysql.yourdomain.com or an IP address. Check your host’s documentation or support knowledge base.A quick way to test these credentials independently is to create a small PHP file in your site’s root directory:
<?php
$connection = new mysqli( 'localhost', 'your_database_username', 'your_database_password', 'your_database_name' );
if ( $connection->connect_error ) {
echo 'Connection failed: ' . $connection->connect_error;
} else {
echo 'Connected successfully.';
}
?>Upload it, visit it in your browser, and see what it reports. Delete this file immediately afterward since it contains your database credentials in plain text.
If your credentials are correct but you still cannot connect, the MySQL service itself might be down. This is more common on VPS or dedicated servers where you manage the server stack yourself. On shared hosting, the host manages MySQL, but outages do still happen.
If you have SSH access, you can check the status of MySQL:
sudo systemctl status mysqlOr for MariaDB:
sudo systemctl status mariadbIf the service is stopped, start it:
sudo systemctl start mysqlIf you are on shared hosting without SSH access, try logging into phpMyAdmin. If phpMyAdmin also fails to connect, the database server is almost certainly down, and you need to contact your host. On a managed hosting plan, the provider handles this for you and typically resolves it quickly.
WordPress has a built-in database repair tool that can fix certain types of corruption. To enable it, add the following line to your wp-config.php file, just above the line that says “That’s all, stop editing!”:
define( 'WP_ALLOW_REPAIR', true );Then visit the following URL in your browser:
https://yourdomain.com/wp-admin/maint/repair.phpYou will see two options: “Repair Database” and “Repair and Optimize Database.” Start with the first option. If that does not resolve things, try the second.
Important: Remove the WP_ALLOW_REPAIR line from wp-config.php once you are done. This page does not require authentication, so leaving it enabled is a security risk.
On shared hosting, your account has resource limits — CPU time, memory, number of simultaneous database connections, and so on. If your site experiences a traffic spike or a runaway process, you can hit those limits. When that happens, new database connections get refused.
Signs that this might be your issue:
Check your hosting provider’s status page to see if there is a known outage. Also look at any resource usage graphs available in your control panel. If your account is consistently bumping up against its limits, it may be time to upgrade your plan or move to a host that gives you more headroom.
Database tables can become corrupted due to server crashes, abrupt shutdowns, or disk issues. If the built-in repair tool from Step 3 did not work, you can try repairing tables directly through phpMyAdmin.
If you have SSH access, you can also use the WP-CLI command:
wp db repairThis runs the MySQL REPAIR TABLE command on every table in your WordPress database. If specific tables are heavily corrupted, you may need to restore from a backup. This is exactly why having regular backups of your website is so critical.
In some cases, WordPress runs out of PHP memory before it can complete the database connection, particularly on sites with large databases or resource-heavy plugins. You can increase the memory limit by adding the following line to wp-config.php:
define( 'WP_MEMORY_LIMIT', '256M' );You can also try setting it in your .htaccess file:
php_value memory_limit 256MOr in a php.ini file in your site’s root directory:
memory_limit = 256MNote that your hosting provider may cap the maximum memory you can allocate. If increasing the limit has no effect, it is likely that your host enforces a lower ceiling, and you will need to contact them or upgrade your plan.
If you have worked through all of the steps above and your site still shows the error, it is time to reach out to your hosting provider’s support team. The issue may be on their end — a misconfigured server, a MySQL process that needs to be restarted, or a permissions problem you cannot fix from your end.
When you contact support, be specific about what you have already tried. This saves time and helps the support agent jump straight to deeper diagnostics. A good hosting provider will have 24/7 support that can check server logs and MySQL status quickly. I have found that hosts like InterServer tend to be responsive when it comes to database-related issues, which matters a great deal when your site is down and every minute counts.
Once your site is back online, it is worth taking a few steps to reduce the chances of this happening again.
If you do not already have automated backups running, set them up now. A full backup — both files and database — taken daily or weekly means you can always restore to a working state. Many hosting plans include backups, but I recommend having your own independent backup as well. I wrote a detailed guide on how to back up your website that covers the best approaches.
Free uptime monitoring services like UptimeRobot or Hetrix Tools can ping your site every few minutes and alert you immediately if it goes down. The faster you know about an outage, the faster you can fix it. Without monitoring, you might not realize your site is down until a visitor or customer tells you — or worse, until you notice a drop in traffic days later.
Never edit wp-config.php or make database changes on your live site without testing first. A staging environment lets you experiment safely. Most managed hosts provide one-click staging. If yours does not, you can set up a separate WordPress installation on a subdomain to use as a testing ground.
Outdated plugins and themes can cause database issues, especially if they use custom tables that fall out of sync. Run updates regularly, but always back up first.
Over time, WordPress databases accumulate overhead — post revisions, transient data, spam comments, orphaned metadata. Plugins like WP-Optimize can clean this up. A leaner database is less prone to corruption and performs better overall.
Indirectly, yes. A poorly coded plugin can corrupt database tables, exhaust your PHP memory, or create runaway queries that hit your host’s resource limits. If the error started right after activating a new plugin or theme, try renaming the wp-content/plugins or wp-content/themes folder via SFTP to deactivate everything, then see if the error clears. If it does, reactivate plugins one at a time to find the offender.
If most of your site loads but specific pages trigger the error, the issue is likely a corrupted table that stores data for those particular pages or a plugin that runs heavy queries on certain templates. Check the tables associated with the content on those pages and try the repair steps outlined above.
Almost certainly not. This error means WordPress cannot connect to the database — it does not mean the database has been deleted or wiped. In the vast majority of cases, all your content is still there, waiting for the connection to be restored. The exception would be severe disk failure on the server, which is extremely rare and something your host’s infrastructure is designed to prevent.
This sometimes happens when the front end is being served from cache. Your site appears to work because visitors are seeing cached HTML files, but the admin panel requires a live database connection. The underlying problem is the same, and you should work through the same troubleshooting steps. Clear your cache after fixing the issue to make sure the front end is also pulling fresh data.
In my experience, the majority of cases are resolved within 15 to 30 minutes. Incorrect credentials in wp-config.php account for a large share of occurrences, and that is a two-minute fix once you identify it. Database server outages on the hosting side may take longer, as you are dependent on the host’s response time. This is one area where the quality of your hosting provider’s support really shows.
The “Error Establishing a Database Connection” message looks alarming, but it is one of the more diagnosable WordPress errors out there. In most cases, it comes down to a credentials mismatch in wp-config.php or a database server that needs to be restarted. Work through the steps in order, and you will likely have your site back up before you have time to panic.
If this error keeps recurring, take it as a signal to evaluate your hosting setup. Reliable database uptime is one of the most basic things a host should provide, and if yours is falling short, it might be time for a change. And regardless of your hosting situation, make sure you have solid backups in place. They are your ultimate safety net when things go sideways.