Fix WordPress Database Connection Error
Error establishing database connection is a common WordPress issue. Here is how to resolve it.
What Causes This Error?
- Incorrect database credentials
- Database server down
- Corrupted database
- Database host change
Solution 1: Check Database Credentials
- Open wp-config.php via FTP
- Verify these values:
define('DB_NAME', 'database_name');ndefine('DB_USER', 'database_user');ndefine('DB_PASSWORD', 'password');ndefine('DB_HOST', 'localhost');
Finding Correct Values
- Log into cPanel
- Go to MySQL Databases
- Check database name
- Verify username
- Reset password if needed
Solution 2: Check Database Host
Common values:
- localhost (most common)
- 127.0.0.1
- Specific IP from host
Contact hosting if unsure.
Solution 3: Repair Database
Add to wp-config.php:
define('WP_ALLOW_REPAIR', true);
Visit: yourdomain.com/wp-admin/maint/repair.php
Remove code after repair!
Solution 4: Check Database Server
- Log into cPanel
- Access phpMyAdmin
- If it loads, database is running
- If not, contact hosting support
Solution 5: Restore from Backup
- Access latest backup
- Restore database via phpMyAdmin
- Import .sql file
Solution 6: Check Privileges
- Go to MySQL Databases in cPanel
- Verify user has ALL PRIVILEGES
- Add user to database again if needed
Final mention: Please feel free to contact us for database troubleshooting.
