Fix “Error establishing a database connection” in WordPress [simple steps]

“Error establishing a database connection” is one of the common WordPress errors while installing/updating WordPress. There are many reasons for this. Following are few reasons and fixes.

Incorrect wp-config.php Information

Most of the times, the main reason for this issue is incorrect data base details in wp-config.php file.
To fix this,
a.  Open your site’s root directory using FTP client
b.  Open wp-config.php file
c.  Find below lines. Note: database_name,username, password and host data will be shown with your site’s actual database credentials.

1.  Make sure database_name, username, password and localhost should match the corresponding mySQL                      database credentials. To find mySQL database credentials using cPanel
a. Goto cPanel.
b. Most of the hosting providers provide Databases section. In that, open MySQL Databases. You ll see list                      of all your databases.
c. Click on the required database to get it’s credentials (name, username, password, host).
d. Compare the database credentials with those in wp-config.php file. If they are not same, update wp-                              config.php file and upload it to root directory.
e. Refresh the wordpress page and check that database connection goes away.
2. If issue still exists, then enable WordPress in debug mode and check for error description. This may give more           details on root cause of database connection error.
3. If the issue is not with database details in wp-config.php, then Contact your web host to check whether server is         down or database quota is over.
4. If above are not the issues, then increase the PHP memory limit and check.

5. If above things don’t work, then take backup and reinstall wordpress

About the Author

SRINI S

A passionate blogger. Love to share solutions and best practices on wordpress hosting, issues and fixes, excel VBA macros and other apps