Here's how to fix error establishing database connection on any WordPress site. While this might be a pain in the ass, there's also a workaround. Click here and find out more.

error establishing database connection

Every day you surf through some website. Be it to find information or any other reason. While surfing, you would have come across some site, which when opened, says “Error Establishing Database Connection.” You cannot surf through that website. For internet surfers this error means nothing, they will just go to another site to access what they're looking for. But for that website owner, this error is a calamity or curse, or you can also say their worst fear.
error establishing database connection
In this article, we will see what is "Error Establishing Database Connection" in WordPress and how to fix this problem.

Every author and a website owner knows what a WordPress is, so I am not going to go into its details.

As we said before, for a website owner, this error is worse than a nightmare. Imagine you go to your job like every day and then suddenly one day the boss says "You Are Suspended", what will be your reaction, you will be losing your work and your revenue. Same is with most of the Website Owners when they get this error. Until they fix this error, they will lose some of their traffic and revenue. You can say that this error gives a close competition to the White Screen of Death(WSOD).

The WordPress software is written using two languages, PHP and MySQL. All the information that make one’s website complete is stored in MySQL database, and WordPress makes use of PHP to store and retrieve this data from the MySQL database.

In general, when you get this "Error Establishing Database Connection" error in WordPress, this means that the PHP is somehow unable to access or connect to the MySQL database. This means that PHP is not able to retrieve the information needed to create the website.

Why does this happen?

There are many reasons for this. Let’s look at some of these reasons.

•    Your Login Credential: Your login credentials are wrong and not able to connect to the database. You used a different login credential (username and password combination) during authentication. If your credential is changed, then you can’t access the database for info and no info means no site.

•    The database is Corrupted: There are several elements that could crash or corrupt your WordPress database. The database can be corrupted due to many reasons like the use of a lousy plugin or a malware. There could also be a problem on your hosted server (hopefully if you have an excellent hosting service then they will fix this problem ASAP). 

•    Corrupt File: Sometimes your database can crash because of a single PHP file. This problem is occurring when malware or a bad plugin damages your PHP file, and by the time we solve the problem, the damage has been done. This PHP file could sometimes be a part of data required to open when accessing your webpage.

•    Hosting Service Error: Sometimes it’s just that the server is unreachable. It may be down for maintenance or is just astounded with lots of traffic and is not able to support new connections. There are also some cases that it is just an issue of your ISP or internet connection or a browser.

There could be much more causes of this error, but the above mention is the primary and commonly occurring reasons.

How to Troubleshoot the “Error Establishing Database Connection” in WordPress?. Here are some of the solutions you can try.

#1. Problem with Login Credential:

If you are having this problem, then it is related to the MySQL credential issues. What could cause this problem? Well, things like changing the hosting service, renaming the name of the database, resetting the password or running the wrong MySQL credential, could cause such problems if the "wp-config" file is not updated to show your new information.

The connection detail of the WordPress is stored in a "wp-config" file; this is located at the root of your WordPress site.

This contains four crucial files that need to be correct for a successful connection.

1.    Database Name

2.    MySQL Database Username

3.    MySQL Database Password

4.    MySQL Hostname (Server)

database connection error problems

Correct these, and you will have a successful connection.

#2. Troubleshoot the corrupt database:

If your wp-config file is alright, but still your public site is not working, search for the problem in the database.  If you are getting an error accessing the "wp-config" file or an error when you try to log in saying “One or more database is missing.” Then WordPress provides you with the easy way to solve this problem. But first, you have to enable this feature.

1.    Go to your host account cPanel and open the File Manager.

cpanel database error

2. Go to Wordpress root directory and look for the "wp-config.php" file. Open it and paste the code: define( ‘WP_ALLOW_REPAIR’, true ); just above the line: "That’s all, stop editing! Happy blogging".

3.    Save changes and close the file. This will enable the feature through which you can Optimize and Repair the database.

4. After the feature is enabled, go to and Click on "Repair Database".

wordpress repair database connection error

#3. Troubleshoot the corrupt file:

If you check and confirms that your database is working fine and syncs well with the credentials, then a bad record has caused this problem.

sql database connection error

Re-uploading the primary WordPress file can solve this problem. If not, then sometimes the problem just has to do with the file permissions or variables in a file that has the settings for essential links or it is only settings error. To solve this, there is a simple step, just reset it.

To reset it in just a single step, follow the instruction below:

1.    First, you have to download the latest version of WordPress.

2.    Unzip the file and save it to your desktop.

3.    From those file delete wp-config.php and wp-content.php.

These files show the changes made on the website, and if you replace these files on your site, you will lose everything.

4.    After you delete those two files, copy the remaining content.

5.    Now go to the host cPanel and upload the file to your WordPress root folder.

You might want to use FTP tools to upload these file, as sometimes doing it manually can cause the error.

So these were the best solution to fix “Error Establishing Database Connection WordPress.” You can also check a good tutorial about this on 000webhost.


Henry Emmanuel

Henry is an avid mobile geek who loves to keep a tab on new gadgets. When he is not fanboying over the latest games online, then you will probably find him watching the Originals and Grey's Anatomy. You can chit-chat with him on Facebook where he speaks out fire.

Get Tech Viola Latest Articles Delivered to Your Inbox!

Post A Comment: