"Error establishing a database connection."
This message sounds terrifying—especially if you're imagining lost data, corrupted files, or a destroyed website. Take a breath. Your data is almost certainly fine.
This error means WordPress can't connect to your MySQL database. The database itself is probably sitting there intact, waiting to be reconnected.
What Causes Database Connection Errors?
WordPress stores all your content—posts, pages, settings, and user information—in a MySQL database. Every time someone visits your site, WordPress connects to that database to retrieve the content it needs.
When that connection fails, you see this error. Common causes:
- Database server is down: The MySQL service stopped running
- Incorrect credentials: The database username, password, or host in wp-config.php doesn't match
- Database host has changed: Your hosting provider moved things without telling you
- Database is corrupted: Rare, but possible at the table level
- Server overload: Too many connections are exhausting available resources
The Most Common Cause (And Easiest Fix)
On budget hosting services like GoDaddy or Bluehost, the most common cause is simply that the database server went down or became unresponsive.
The fix: Call your host's tech support and ask them to restart database services.
In 90% of cases, this solves the problem immediately. It's not something you did wrong—it's an infrastructure issue on their end.
We rarely see this error on properly managed hosting because our infrastructure includes self-healing containers and constant monitoring. If a database service hiccups, it restarts automatically within minutes—often before anyone notices.
Check Your wp-config.php Credentials
If restarting the services doesn't help, the next step is to verify your database credentials.
Open your wp-config.php file (in your WordPress root directory) and find these lines:
define('DB_NAME', 'your_database_name');
define('DB_USER', 'your_database_username');
define('DB_PASSWORD', 'your_database_password');
define('DB_HOST', 'localhost');
These values must match exactly the values configured in your hosting account's database settings.
Common Credential Problems
Changed passwords in cPanel: If someone reset the database password through your hosting control panel, that new password needs to be updated in wp-config.php. The hosting panel and WordPress don't automatically sync—you have to update both.
Host moved the database: Some hosts move databases during server migrations or upgrades without notifying customers. The DB_HOST value might have changed from localhost to something like mysql.yourhost.com.
Typos: It happens. Double-check everything carefully, including capitalization.
Testing the Connection
If you're not sure whether your credentials are correct, most hosting control panels let you test database connections:
- Log in to your hosting control panel
- Go to MySQL Databases or Database Manager
- Try logging in with the credentials from wp-config.php
If you can log in through the panel but WordPress can't connect, the issue might be the DB_HOST value. Contact your host to confirm what it should be.
Database Corruption (Rare)
If credentials are correct and the database server is running, the issue might be database corruption.
This is rare on modern hosting—MySQL is incredibly stable, and the servers it runs on are designed for reliability. We haven't seen a database corrupted to the point of no return in probably ten years.
That said, corruption at the table level does happen occasionally. WordPress can sometimes repair itself:
- Add to wp-config.php:
define('WP_ALLOW_REPAIR', true); - Visit:
yoursite.com/wp-admin/maint/repair.php - Run the repair
- Remove that line from wp-config.php when done
If repair doesn't work, you'll need to restore from a backup. This is where having reliable, recent backups becomes critical.
When to Call for Help
Database connection errors are usually straightforward to diagnose, but the fixes require server-level access and knowledge.
If you're not comfortable:
- Editing wp-config.php
- Navigating your hosting control panel
- Testing database connections
Then it's time to contact your hosting provider's support or a WordPress professional.
These errors feel scary because they completely take down your site, but they're typically resolved quickly once someone with the right access investigates.
Prevention
- Use quality hosting: Budget hosts have more database downtime
- Keep backups current: If the worst happens, you can restore
- Document credentials: Know where your database credentials are stored
- Work with managed hosting: Proper hosting includes monitoring and automatic recovery
With properly managed WordPress hosting, database connection issues trigger immediate alerts. Our monitoring often catches and resolves these problems before clients even know something went wrong.
Dealing with a database connection error? Contact our support team for fast resolution.
This article is part of our WordPress Troubleshooting guide—a complete resource for diagnosing and fixing common WordPress errors.