Most of the time, this problem happens when your website can’t connect to its database. We’ll look into why this happens and how to fix it properly.
What Causes of This Error?
There are many reasons included for this error:
- Incorrect Database Credentials: If your database name, username, password, or host credentials are incorrect. You will show this error.
- Database Server Issues: If your hosting provider’s database server has an error or is down at this time.
- High Website Traffic: This occurs when the number of visitors to your website is so high that the database server is unable to handle them.
- Misconfigured Configuration File: The wp-config.php file can’t be setup correctly.
How to Fix Error Establishing a Database Connection Error
In this step-by-step guide, I will show you fixing Error Establishing a Database Connection Error in WordPress:
1. Check Database Configuration and Credentials
- Access your wp-config.php file. hosting > root directory > wp-config.php.
- Check your database name, username, password and host are matched to your database credentials.
- If this file has any incorrect information, please update with the correct information.
define('DB_NAME', 'your_database_name');
define('DB_USER', 'your_db_username');
define('DB_PASSWORD', 'your_db_password');
define('DB_HOST', 'localhost');
2. Test the Database Connection
Go to your root folder and create a file called testdb.php and paste this code in your file:
<?php
$link = mysqli_connect("localhost", "your_username", "your_password", "your_database_name");
if (!$link) {
die("Connection failed: " . mysqli_connect_error());
}
echo "Connected successfully";
?>
Then run testdb.php file with this link . 🤏 http://yourdomain.com/testdb.php
4. Contact Your Hosting Provider
- If all steps are not working, please contact your hosting provider; they can solve it.
5. Upgrade Your Hosting Plan
- If your site receives a high volume of visitors, it may display this error. You might want to upgrade your hosting plan so that it can handle more connections. Reducing and optimising your database may solve this error.
Final Thoughts:
“Error Establishing a Database Connection” happens a lot, but it’s simple to fix. By doing these steps, you can find and fix the problem, making sure that your website stays live and users can access it.
If you’re still having issues, you might want to get help from a professional developer or your hosting service.