How to fix "Error Establishing A Database Connection" error in WordPress

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.  

  • 0 Users Found This Useful
Was this answer helpful?

Related Articles

How do I prevent WordPress from overloading my shared server?

WordPress blogs can be extremely resource intensive if you happen to experience a surge in...

How to Prevent Wordpress Hacking

These are 10 Tips To Increase Wordpress SecurityIn recent years there has been a proliferation of...

What is Wordpress?

WordPress is an open source blog tool and publishing platform powered by PHP and MySQL. It is...

How to Manually Install WordPress in Parallel Plesk Panel?

Installing WordPress manually in Parallel Plesk Panel allows for greater customization and...

How to reduce wordpresss server load on shared hosting

For everyone of you, who use wordpress as a platform with shared hosting for his/her blog will...