Fix the WordPress Error Establishing a Database Connection

| Last Updated: | In: Wordpress, WP Labs


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.

wordpress-database-repair

After doing above you will be able to access a wordpress database repair page on your website by open this url http://yoursiteurl.com/wp-admin/maint/repair.php and click on Repaire Database button. WordPress can automatically look for common database errors and repair them.

wordpress-database-repair-success

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

Tags: , , ,


About: Prem Tiwari

Prem Tiwari is founder of freewebmentor.com and Software developer from New Delhi (India). Follow Prem's development codes on facebook, and make sure you check out freewebmentor.com for the latest in web development related Tips with the complete code.


You may also like:

Follow us!

Get Free Access of 350+ Scripts

Don't worry you'll not be spammed!

Featured eBook

WordPress Security Guide

Learn how to implement security guideline in your WordPress site...

DOWNLOAD

Pincode Finder

pincode-finder tool

Online Pincode Finder

Best tool to locate post Office address and pincodes of all india...

SEARCH NOW