Error establishing a database connection
You try to visit your site, and instead of the usual homepage, you’re greeted with an error message like:
“Error establishing a database connection.”
What does that even mean, and how can you fix it?
This error typically occurs when WordPress is unable to communicate with your database. It might be due to incorrect login credentials, server issues, or a corrupted database. Luckily, most of the time, it’s a fixable problem. Here’s how you can troubleshoot and resolve the issue.
Step 1: Check your wp-config.php file
- Go to your WordPress root directory via FTP or File Manager.
- Locate the wp-config.php file and open it.
- Check the following settings to make sure they’re correct:
DB_NAME – The name of your database.
DB_USER – The database username.
DB_PASSWORD – The password for your database user.
DB_HOST – This is usually localhost, but some hosts might use a different value (check with your host if unsure). - Make sure these credentials match what’s set up in your database.
Step 2: Test your database connection manually
If you’re still having trouble, try to connect to your database manually using a tool like phpMyAdmin (available through your hosting control panel):
Open phpMyAdmin in your control panel (cPanel or DirectAdmin) and try logging in with the credentials from your wp-config.php file.
If the login fails, check your database username and password for accuracy.
If you can’t log in, please contact our support team for assistance.
Step 3: Repair the database
Sometimes, a corrupt database can cause connection issues. WordPress has a built-in repair tool that can help fix database problems.
- Open your wp-config.php file.
- Add the following line before /* That’s all, stop editing! */:
define('WP_ALLOW_REPAIR', true);
- Save the file and visit this URL: http://yoursite.com/wp-admin/maint/repair.php
You’ll see an option to repair and optimize the database. Don’t forget to remove the line from your wp-config.php file once you’re done.
Step 4: Check for database server issues
If your credentials are correct and your database is working, the issue might be with your server. Sometimes, the database server can go down temporarily.
Check server status: Contact our support team to see if there are any ongoing issues.
Wait a while: Sometimes, these issues resolve themselves if the server is temporarily overloaded.
Step 5: Restore from a backup (if needed)
If none of the above steps work, and you’ve recently experienced problems with the database, restoring from a backup might be your best bet.
Or you may contact our support team. We have several daily backups of your hosting service ready to be restored anytime.