How do I fix “Error establishing a database connection” in WordPress?
25 viewsHow do I fix “Error establishing a database connection” in WordPress?
Overview
This error means your WordPress site cannot connect to its database. Without this connection, your website cannot load content such as pages, posts, or settings.
Common Causes
This issue is usually caused by:
- Incorrect database login details in WordPress
- Database server being down or overloaded
- Corrupted WordPress database
- Full disk space on your hosting account
Step-by-Step Fixes
1. Check your WordPress database details
- Log in to your File Manager in DirectAdmin
- Open the file:
wp-config.php (located in
public_html) - Check these values:
- DB_NAME
- DB_USER
- DB_PASSWORD
- DB_HOST
Make sure they match your actual database details in DirectAdmin.
2. Verify your database in DirectAdmin
- Log in to DirectAdmin
- Go to: Account Manager → MySQL Management
- Check that:
- The database exists
- The user is assigned correctly
- The password matches wp-config.php
3. Repair the WordPress database
If the database is corrupted:
Option A (recommended)
- Add this line to
wp-config.php:
define('WP_ALLOW_REPAIR', true);
- Visit:
yourdomain.com/wp-admin/maint/repair.php
- Click Repair Database
- Remove the repair line afterward for security
4. Check disk space
If your hosting is full:
- Log in to DirectAdmin
- Check disk usage
- Delete unused files, backups, or emails
5. Restart or check server status
Sometimes the issue is temporary:
- Server overload
- Database service downtime
If everything looks correct, wait a few minutes and retry.
Important Notes
- Even a small typo in database credentials will break your site
- Always back up your site before editing
wp-config.php - Avoid leaving repair mode enabled after use
Common Issues & Fixes
Still seeing the error after fixing credentials
- Clear browser cache
- Check if database user has correct permissions
Only admin works, site doesn’t
- Theme or plugin issue may be interfering
- Try disabling plugins via File Manager
Error appeared after migration
- Double-check database name and host settings
Need Help?
If you’re unable to resolve the error, our support team can check your database connection and restore your website for you.