The “Error Establishing a Database Connection” is one of the most critical WordPress errors. When this happens, your website completely stops working and shows a blank error message instead of your content.
This error means WordPress cannot connect to your database, which stores all your website data like posts, pages, users, and settings.
What is a Database Connection Error?
WordPress works using two main parts:
- Website files (themes, plugins, code)
- Database (content, settings, users)
When WordPress cannot access the database, it shows:
“Error Establishing a Database Connection”
In simple words:
Your website exists, but it cannot retrieve data from the database.
Common Causes of Database Connection Error
This error usually happens due to:
- Wrong database credentials
- Corrupt database
- Database server down
- Overloaded hosting server
- Corrupted WordPress files
- Incorrect wp-config.php settings
- Hacked website changes
Step 1: Check Database Credentials in wp-config.php
The most common issue is incorrect login details.
Open wp-config.php file and check:
- Database name
- Database username
- Database password
- Database host
If any of these are wrong, connection will fail.
How to Fix It
Go to your hosting panel:
- Open MySQL Databases
- Check correct database name
- Verify username and password
- Update wp-config.php accordingly
Even a small typo can break the connection.
Step 2: Check Database Server Status
Sometimes the issue is not your website, but the hosting server.
Possible problems:
- MySQL server is down
- Server overload
- Maintenance by hosting provider
Fix:
- Contact hosting support
- Ask if database server is running
- Wait if it is temporary outage
Step 3: Repair WordPress Database
WordPress has a built-in repair feature.
Enable repair mode:
Add this line in wp-config.php:
define('WP_ALLOW_REPAIR', true);
Then open:
yourdomain.com/wp-admin/maint/repair.php
You will see:
- Repair Database
- Repair and Optimize Database
Run both options.
After fixing, remove the code from wp-config.php.
Step 4: Check Corrupted Database Tables
Sometimes tables inside database get corrupted.
Fix via phpMyAdmin:
- Open phpMyAdmin
- Select your database
- Check all tables
- Select “Repair Table” option
This fixes broken database structure.
Step 5: Restore Backup
If database is badly damaged:
Solution:
- Restore latest backup from plugin or hosting
- Use UpdraftPlus or backup system
- Or restore via cPanel backups
This is often the fastest fix.
Step 6: Check Hosting Resource Limits
Shared hosting can sometimes hit limits.
Symptoms:
- Slow website
- Frequent database errors
- Server timeouts
Fix:
- Upgrade hosting plan
- Optimize database size
- Reduce heavy plugins
Step 7: Check WordPress Core Files
Corrupted WordPress files can also break database connection.
Fix:
- Download fresh WordPress copy
- Replace wp-admin and wp-includes folders
- Keep wp-content unchanged
This restores system integrity.
Step 8: Check for Hacking or Malware
Hackers can change database settings.
Signs:
- Unknown admin users
- Suspicious files
- Sudden configuration changes
Fix:
- Scan website using security plugin
- Remove malware
- Change all passwords
- Restore clean backup
Step 9: Restart Database Service (Advanced)
If you have VPS or dedicated hosting:
- Restart MySQL service
- Restart web server (Apache/Nginx)
This can fix temporary crashes.
Step 10: Contact Hosting Provider
If nothing works:
Ask hosting support to check:
- MySQL logs
- Server status
- Resource usage
- Database integrity
They can often fix it quickly.
How to Prevent Database Errors
- Keep backups regularly
- Use stable hosting
- Avoid too many heavy plugins
- Keep WordPress updated
- Monitor server performance
- Use strong security protection
Common Mistakes
- Editing wp-config.php incorrectly
- Ignoring backup systems
- Overloading server with plugins
- Not checking hosting limits
- Delaying updates
Pro Tips
- Always backup before changes
- Use staging site for testing
- Monitor database size regularly
- Optimize database monthly
- Use caching plugins
Conclusion
The database connection error is one of the most serious WordPress issues, but it is usually caused by simple problems like wrong credentials, server issues, or corrupted tables.
By checking wp-config.php, repairing the database, and verifying hosting status, you can quickly restore your website.

