Why Does My Site Show 'Error Establishing Database Connection'?
Fix the dreaded 'Error establishing a database connection' WordPress error. Learn the causes and step-by-step solutions to get your site back online.
"Error establishing a database connection" is one of the most common and frustrating WordPress errors. Your site is completely down, and you need to fix it fast.
Here's what causes this error and how to fix it, step by step.
What This Error Means
WordPress stores all your content (posts, pages, settings, users) in a MySQL database. When WordPress can't connect to that database, you see this error.
The database connection requires:
- Correct database name
- Correct database username
- Correct database password
- Database server running
- Enough server resources
If any of these fail, you get the error.
Quick Diagnosis
Check if Database Server is Down
Test 1: Can you access phpMyAdmin?
- Log into hosting control panel (cPanel)
- Click phpMyAdmin
- If it loads, database server is running
Test 2: Check admin vs frontend
- If
yoursite.com/wp-admin/shows different error mentioning "repair," database may be corrupted - If both show same error, likely credentials or server issue
Common Causes & Fixes
Cause 1: Wrong Database Credentials
Most common cause. The wp-config.php file has incorrect database settings.
How it happens:
- Password was changed
- Database was moved
- Typo in credentials
- Migration issues
Fix:
-
Access your files via FTP/SFTP or File Manager
-
Open wp-config.php in root directory
-
Find these lines:
define('DB_NAME', 'your_database_name');
define('DB_USER', 'your_username');
define('DB_PASSWORD', 'your_password');
define('DB_HOST', 'localhost');
-
Verify credentials in cPanel:
- Go to MySQL Databases
- Check database name matches DB_NAME
- Check username matches DB_USER
- Note: Password isn't shown, may need to reset
-
Reset password if unsure:
- In cPanel → MySQL Databases
- Find the user → Change Password
- Update wp-config.php with new password
-
Save and test
Cause 2: Database Server is Down
Your hosting's MySQL server is temporarily offline.
Symptoms:
- Error appeared suddenly
- No changes were made
- Multiple sites affected (if you have several)
Fix:
- Wait 5-10 minutes - Often resolves itself
- Check host's status page for outages
- Contact host support if persists
- Check resource limits - May be suspended for overuse
Cause 3: Corrupted Database
Database tables can become corrupted, especially after crashes or resource limits.
Symptoms:
- wp-admin shows: "One or more database tables are unavailable. The database may need to be repaired."
Fix Option 1: WordPress Repair
- Add to wp-config.php (before "That's all, stop editing!"):
define('WP_ALLOW_REPAIR', true);
-
Visit:
yoursite.com/wp-admin/maint/repair.php -
Click "Repair Database" or "Repair and Optimize"
-
Remove the line from wp-config.php when done (security risk if left)
Fix Option 2: phpMyAdmin Repair
- Open phpMyAdmin
- Select your WordPress database
- Select all tables (check boxes)
- Choose "Repair table" from dropdown
- Execute
Cause 4: Exceeded Database Connections
Too many simultaneous connections to database.
Symptoms:
- Error comes and goes
- Happens during traffic spikes
- May see "Too many connections" in logs
Causes:
- Traffic spike
- Poorly coded plugin
- Bot attack
Fixes:
-
Wait for traffic to subside
-
Increase max connections (if you have access):
max_connections = 500
-
Optimize slow queries:
- Install Query Monitor plugin
- Identify slow database queries
- Fix or remove problematic plugins
-
Upgrade hosting if consistently hitting limits
Cause 5: Database Host Wrong
The DB_HOST value in wp-config.php is incorrect.
Common values:
localhost- Most shared hosting127.0.0.1- Same as localhostmysql.yourdomain.com- Some hosts- Specific IP or hostname - Cloud/VPS setups
Fix:
- Check your host's documentation
- Contact support for correct value
- Common hosts:
- Most shared:
localhost - GoDaddy: Often specific hostname
- SiteGround:
localhost - Bluehost:
localhost
- Most shared:
Cause 6: Insufficient Server Resources
Your hosting plan ran out of memory, CPU, or disk space.
Symptoms:
- Multiple issues, not just database
- Error in server logs about resources
- Host sends warning emails
Fixes:
-
Check disk space:
- cPanel → Disk Usage
- Clear old backups, logs, unused files
-
Check resource usage:
- cPanel → Resource Usage
- Identify spikes or overuse
-
Upgrade plan if consistently maxed out
-
Optimize site:
- Remove unused plugins
- Optimize images
- Add caching
Cause 7: Plugin or Theme Conflict
A recent plugin/theme update corrupted database or causes excessive queries.
Symptoms:
- Error started after update
- Error after activating plugin
Fix:
-
Access files via FTP
-
Rename plugins folder:
/wp-content/plugins/ → /wp-content/plugins_disabled/
-
Check if site loads
-
If yes, rename back to plugins/
-
Rename plugins one by one to find culprit:
/wp-content/plugins/problem-plugin/ → /wp-content/plugins/problem-plugin_disabled/
- Delete or replace problematic plugin
Advanced Troubleshooting
Check MySQL Error Logs
In cPanel:
- Go to Errors in cPanel
- Check for MySQL-related errors
Via SSH:
tail -100 /var/log/mysql/error.log
Test Database Connection Manually
Create a test file test-db.php in your root:
<?php
$link = mysqli_connect('localhost', 'your_user', 'your_password', 'your_database');
if (!$link) {
die('Connection failed: ' . mysqli_connect_error());
}
echo 'Connected successfully';
mysqli_close($link);
?>
Visit yoursite.com/test-db.php - delete after testing!
Check if Database Exists
- Log into phpMyAdmin
- Look for your database name in left sidebar
- If missing, database may have been deleted
- Restore from backup
Prevention
Regular Backups
Use backup plugins or host backups:
- UpdraftPlus (free)
- Host's backup feature
- BlogVault (premium)
Monitor Database Health
- Use WP-Optimize plugin for maintenance
- Schedule regular database optimization
- Keep plugins updated
Use Quality Hosting
Reliable hosts have:
- Better MySQL configurations
- More stable servers
- Proactive monitoring
Consider: SiteGround, Kinsta, Cloudways
FAQ
Why did this happen suddenly?
Common sudden causes:
- Host server issue
- Resource limit hit
- Automatic password rotation (rare)
- Database corruption from crash
Can I lose my content?
If the database is deleted or severely corrupted, yes. This is why backups are critical. In most cases, the data is fine—it's just a connection issue.
Should I contact my host?
Yes, if:
- You've checked credentials and they're correct
- phpMyAdmin doesn't work either
- Error persists after basic troubleshooting
How do I prevent this?
- Use reliable hosting
- Keep regular backups
- Update WordPress/plugins regularly
- Don't over-install plugins
- Monitor server resources
The error says my database needs repair. Is that serious?
Usually fixable with the repair function. If repair fails, restore from backup.
Quick Fix Checklist
- Check if phpMyAdmin works (is MySQL running?)
- Verify wp-config.php credentials match cPanel
- Try resetting database user password
- Check DB_HOST value is correct
- Try database repair
- Disable plugins via FTP
- Check server resources/disk space
- Contact hosting support
Key Takeaways
- Usually credential mismatch - Check wp-config.php first
- Database server issues - Contact host if credentials are correct
- Corruption is fixable - Use WordPress repair or phpMyAdmin
- Backups save you - Always have recent backups
- Quality hosting helps - Fewer database issues on good hosts
What to Do Next
- Run through the checklist above
- Contact host support if stuck
- Restore from backup if data is corrupted
- Consider better hosting if this happens frequently
Having recurring database issues? It might be time to upgrade your hosting. Compare options with our hosting comparison tool or take the hosting quiz for recommendations suited to your needs.
Last updated: January 2026

HostDuel Team
The HostDuel team researches and compares web hosting providers to help you make informed decisions.