The error you’re encountering, “Error Establishing a Database Connection”, is a common WordPress issue that means your website is unable to connect to the MySQL database.
Here are some possible reasons for this error:
- Incorrect database login credentials: WordPress needs the correct login and password to access the database. If those have changed for some reason, WordPress may not be able to fetch anything from the database.
- Corrupted WordPress files: WordPress core files can corrupt for various reasons. If that’s the case, you might get this error.
- Database server is down: If your database server is unresponsive, WordPress won’t be able to access the database hence the error.
Here’s how to troubleshoot this issue:
- Check your WordPress Database Credentials: Open your
wp-config.phpfile and check the database name, host, username, and password. Make sure they match with the credentials you used when setting up your MySQL database on XAMPP. - Repair the WordPress Database: You can attempt to repair the database using a built-in WordPress feature. To enable this, open
wp-config.phpand just before'That's all, stop editing! Happy blogging.', add the following line:
define('WP_ALLOW_REPAIR', true);
Then, navigate to http://yourwebsite.com/wp-admin/maint/repair.php and click “Repair Database” or “Repair and Optimize Database”. Note: this feature should be used with caution, and it’s recommended to have a backup before proceeding. After you’re done, make sure to delete the line you added to wp-config.php.
- Check your Database Server: If you have other websites running on the same server, check if they are also experiencing the same problem. If they are, the database server itself could be unresponsive. If you’re running locally and this issue occurs, it could be that your MySQL server isn’t running or has crashed. Restarting your XAMPP might fix it.
If none of these solutions work, there might be a more complex issue at hand, and you might want to seek professional help. Remember to backup all your WordPress files and the database, before trying any troubleshooting steps to avoid losing data.


