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.


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.

Tags: , , ,

About: Prem Tiwari

Prem Tiwari is the founder of and is a professional developer who has vast experience in PHP and open source technologies. Apart from this, he is a blogger by hobby.

You may also like:

Get Free Access of 450+ Scripts

Don't worry you'll not be spammed!

Featured eBook

WordPress Security Guide

Free Guide: Learn how to implement security guideline in your WordPress site...


Free WordPress Setup Service

Free WordPress Setup

Want to Setup WordPress Blog Setup? I will help you in the setup of your WordPress blog.

Click Here

Discount Coupons

Pincode Finder

pincode-finder tool

Online Pincode Finder

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