Knowledge Base
How to Fix WordPress Database Connection Error
Resolving Database Issues
"Error establishing a database connection" means WordPress can't connect to MySQL.
Common Causes
- Wrong database credentials in wp-config.php
- Corrupted database
- Database server down
- Database user permissions
Step 1: Verify Database Credentials
Check wp-config.php for:
define('DB_NAME', 'database_name');
define('DB_USER', 'database_user');
define('DB_PASSWORD', 'password');
define('DB_HOST', 'localhost');
Step 2: Test Database Connection
- Log into DirectAdmin
- Go to MySQL Management
- Try accessing phpMyAdmin
- If it works, credentials are the issue
Step 3: Check Database User
- Go to MySQL Management
- Verify the database user exists
- Check user permissions
- Reset password if needed
Step 4: Repair Database
Add to wp-config.php:
define('WP_ALLOW_REPAIR', true);
Then visit: yourdomain.com/wp-admin/maint/repair.php
Remove the line after repair!
Step 5: Check Database Server
If none of the above works, the database server may be down. Contact support.
Prevention
- Don't edit wp-config.php unless necessary
- Regular backups
- Monitor database size