How to fix Error Establishing A Database Connection in WordPress
During the wordpress installation the most common error that anyone can face id “Error
Establishing Database connection”. Normally this error occurs when the connection string is not working in wp-config.php file. Before changing anything, Make sure that the following conditions are met. However in this article we will show you the way how you can rectify this error and make a smooth wordpress installation and get things working.
- First of all make sure you have backup of your code and database before you proceed.
- Database name matches the existing database name
- Username of the assigned database user matches the existing database username
- Password matches the one assigned to the specified database user
- Specified user has access privileges to the site’s database
- Wp-config-sample.php file can also be one cause of the problem, this file should exist there.
- If you are performing these steps on localhost,( Xamp, Wamp) make sure that you restart all services after performing these steps.
Database name, database username and its password can be found in the wp-config.php file located in the root directory of your WordPress installation. In order to check these details, do the following:
STEP – 1
Log into your cPanel and navigate to File Manager menu:
STEP – 2
Move to the root folder or public_html for your WordPress installation.
STEP - 3
Click on the wp-config.php file with the right-mouse button and select Edit or View option:
STEP - 4
The file should contain the name, username and password of the database assigned to your WordPress installation. Don’t change anything else in the file unless you have clear understanding of the changes that you are going to made.
Once you have found the database details in the wp-config.php file, the next step is to check if they are correct.
STEP - 5
Go to MySQL Databases option in cPanel:
STEP – 6
Carefully check if there is a database which name fully matches the one specified in wp-config.php file:
STEP - 7
Then scroll down and check the database username:
STEP - 8
Set the password to the one specified in wp-config file:
Make sure that you choose a strong password with the combination of letters, numbers and characters and it should not be a dictionary word. This will help to avoid dictionary attack on your site.
STEP - 9
lastly, it is necessary to make sure that the specified user has ALL the access privileges to the database:
STEP - 10
Click on the All Privileges checkbox and apply the changes. Once done, you will get the message stating that MySQL User has been successfully added to the Database with all the privileges:
Perform this step carefully because the user must have ALL privileges on the database in order to perform the CRUD tasks normaly. Once the database, the username and the password have been changed to the correct ones, then the Error Establishing a Database Connection error on your WordPress site should be fixed.