If your WordPress site is displaying ‘Error establishing a database connection’, follow these steps to resolve it.
Step 1: Check If the Database Server is Down
Try accessing phpMyAdmin from your hosting panel.
If phpMyAdmin doesn’t load, your database server may be down. Contact your hosting provider.
Step 2: Verify Database Credentials in wp-config.php
Access your site via FTP or File Manager.
Open the wp-config.php file.
Check the following database details: define(‘DB_NAME’, ‘your_database_name’);
define(‘DB_USER’, ‘your_database_user’);
define(‘DB_PASSWORD’, ‘your_database_password’);
define(‘DB_HOST’, ‘localhost’);
If any values are incorrect, update them with the correct credentials from your hosting panel.
Step 3: Repair the WordPress Database
Open wp-config.php and add this line before */ That’s all, stop editing! */**: define(‘WP_ALLOW_REPAIR’, true);
Visit yourwebsite.com/wp-admin/maint/repair.php and click Repair Database.
After completing the repair, remove the WP_ALLOW_REPAIR line from wp-config.php.
Step 4: Restart the Database Server
Log in to your hosting control panel.
Navigate to MySQL Databases and restart the database service (if your host allows it).
Step 5: Check Database Table Prefix
In wp-config.php, find the line: $table_prefix = ‘wp_’;
Ensure the prefix matches the one in your phpMyAdmin database.
If it doesn’t match, update wp-config.php to use the correct prefix.
Step 6: Restore a Backup
If you have a recent backup, restore your database from it.
Many hosting providers offer automated backups in cPanel or Plesk.
Step 7: Contact Your Hosting Provider
If none of the above steps work, contact your host and provide them with the error message.
Ask if there are any ongoing database server issues or restrictions.
Conclusion
These steps should help fix the ‘Error Establishing a Database Connection’ in WordPress. If the problem persists, it could be due to server-side limitations or corruption in the database.
0 Comments