Fix the WordPress Error Establishing a Database Connection

Hi friends, today i am sharing the solution of database connection error in wordpress. One of my client got “Error Establishing a Database Connection” in his wordpress website intermittently. While doing R&D to find the root causes of this error, i realized that there are many ways to fix this error. Bellow is the lists of few possible solutions.

Important Note: Please take sufficient database backups before make any database changes.

1. Check Your wp-config file

Navigate root directory of your website and open wp-config.php file and make sure all database configuration details are correct in bellow code.

Please note that your database hostname will be different. It is depending on the hosting server.

2: Create A New Database User And Password

Open your website cpanel and click on “MySQL® Databases.” then Add New User with strong password and assign that database with new created user. After done above open your wp-config file and update database details with the new username and password.

3. Due to Corrupted Database

In this case you must be repaire your database by using bellow steps. Navigate the root directory of your website and open wp-config.php file. Add the bellow code at the end of wp-config.php file and save.


After doing above you will be able to access a wordpress database repair page on your website by open this url and click on Repaire Database button. WordPress can automatically look for common database errors and repair them.


If you are still getting the same error message, then check with your hosting company.

If you like FreeWebMentor and you would like to contribute, you can write an article and mail your article to [email protected] Your article will appear on the FreeWebMentor main page and help other developers.

Recommended Posts:

Article Tags: , , ,