How to debug WordPress Error  “Error establishing a database connection”

via itechiesnet    Discuss    Blogging
As a newbie, the ‘Error establishing a database connection’ in WordPress can be a big headache for you, especially if it happens on its own without you change anything.

If you have recently encountered this error in your WordPress, don’t panic at all. All you need to do is read this article until the end. I will provide you some exceptionally easy options to resolve this error.

But before that let’s see what this error actually is.

The ‘Error establishing a database connection means your site has no longer access to your database and for that reason, your website has gone down. It usually happens when a PHP code is unable to connect to your MySQL database.

There can be many possible scenarios that can cause this error. Some of the common are:


Corrupt Database-Anything which can cause your WP database to become corrupted
The server which hosts your database is down-It generally happens when the server of your hosting company is unable to handle heavy traffic on your website.
Inaccurate Login Credentials of your database- Many people don’t know but the database has separate login credentials (username & password). If for some reason those credentials have gone changed, your site will not be able to access the database through the old credentials.


How to Fix ‘EEDC’ Error in WordPress
See If Your Database is Corrupted
As said above, you corrupted database could be responsible for this error you should not forget to check it.

It is fairly easy to check if your database connection is actually broken or just corrupted.

Let’s find out how?

Go to If you are seeing the exact same error when you access your dashboard it means it is not simple corruption problem.

On the other hand, if you see a different error like one or more database tables is unavailable then it means your database is corrupted rather than entirely unavailable.

Fortunately, fixing a corrupted database is fairly easy. You just need to add one more line to the wp-config.php file. If you’re using FTP (File Transfer Protocol) you can simply download the file to your computer.

However, I will suggest you use your cPanel’s built-in File Manager tool:

Launch File Manager accurately, don’t forget to select the domain name in question. Click on ‘File Manager’ folder, it will take you to the following window:

Here you have to search for  wp-config.php file. Click on it and select the button ‘Edit’ from the top.


It will give you access to copy edit this file. Next, you have to add the following code at the bottom of this file. This is a command to enable the database repair function.

Now click on ‘Save’ button available on the top. Save the wp-config.php file. Next, you have to type the following URL:

It will take you to the following screen where you have to click on the ‘Repair Database Button’

This repair process may take minute or less. After the completion of repair process, the error should hopefully be resolved. Don’t forget to go back to the wp-config.php file to delete the code you had added.


If it is not working for you, then probably incorrect database details in wp file are responsible for “Error establishing a database connection”. Find the solution for the same in the below section.

Check If Your Database Details in wp-config.php File are Accurate

Wrong database details in the wp-config.php file could be another possible cause for this error. Usually, if your database details don’t match with wp file, WordPress does not connect to your database resulting in ‘Error establishing a database connection’.

Don’t panic, fixing it is fairly easy just follow the steps given below.

Again you have to open wp-config.php file. You may use the same method I mentioned above to open the file.

Here you will find all your credentials (Database name, Username and your Password) in plain text as shown in the above screenshot.

There are many other ways to test if the existing credentials are accurate or not but they can be little problematic for newbies.

Therefore, I have chosen this method. Moreover, it helps you achieve two aims at once i.e.

You can ensure:

Your database details are accurate.
Your database user has the right permissions.


First, confirm you are seeing the database name in wp-config.php file in the list of ‘Current Databases’ under your cPanel.

If it is not present there, then you will have to create it manually.


See how you can create a new user:



Scroll to MySQL user and enter the details. Make sure all the access privileges are accurate.

Choose new username and password and hit ‘Create a User’ button. Next scroll down to the next step i.e. ‘Add a User to a Database’. Here you have to add your new credentials to your existing database.

In the next screen, don’t forget to check the box to give yourself 'All privileges’. However, if you are giving access to your employees then you may limit their access to your website by checking only a few privileges.


Next, go back to the editable wp-config.php file which you had opened in File Manager. Update your username and password.

In the next screen, don’t forget to check the box to give your user ‘All privileges’. However, if you are giving access to your employees then you may limit their accessibility to your website by checking only few privileges.

Next, go back to the editable wp-config.php file which you had opened in File Manager. Update your username and password.

Now you have the same credentials both in the wp-config.php file and in the database. Load your website to check if the error has gone.

The above tips should help you get over the issue.

If you’re looking for an extensive information on the same topic, 000webhost comes up with some other options for fixing the Error Establishing a Database Connection Problem in WordPress.

If you’re still getting this problem check with your hosting provider. Perhaps poor hosting service is responsible for this error. If you have more suggestions on how to fix Error establishing a database connection, share with us.

We would love to hear from you!


Submit a Comment

Log in to comment or register here