The "Error establishing a database connection" can be easily pinpointed to a few things worth checking first:
- Check the current database parameters.
- Open the wp-config.php file
- Match parameters of your actual database with the configuration file.
Let’s take a look at these steps closer:
Step 1 - Checking the current database parameters
Go to the list of databases:
You will need these credentials:
In order to save these, you can copy them to a TXT file or leave the databases tab open on your browser.
Step 2 - Open configuration file
Now it is time to open File Manager and the wp-config.php file. You will be able to find it by opening Hosting → Manage → File Manager:
It will be located in your public_html folder, named wp-config.php:
Step 3 - Matching the credentials
In the configuration file, find the fields responsible for your website connecting to the database and specify the correct data.
Needed fields will be DB_NAME, DB_USER, DB_PASSWORD and DB_HOST. You need to specify the correct values in this way:
DB_NAME - MySQL Database;
DB_USER - MySQL User;
DB_PASSWORD - The password that you specified when creating the database;
DB_HOST - MySQL Server.
Once filled up, it will look like this:
After the new values are set, save the changes, and reload the site page using Ctrl + F5 buttons.
If the error persists
If the error persists after you’ve gone through all the steps it usually means that the password you’ve set to your database is different from the one set in the configuration file.
No worries, you can easily fix it by opening up your configuration file and copying the current password:
- Make sure to copy the password only (without any symbols like “)“ or similar)
And then change the password.
That’s it! Now you know how to fix Error establishing a database connection error on WordPress 😊