Drupal to Adopt React JS framework for Administrative UI’s
Drupal to Adopt React JS framework for Administrative UI’s
October 4, 2017
Windows Phone to Rest in Peace (finally)
Windows Phone to Rest in Peace (finally)
October 10, 2017

How to Fix WordPress error establishing a database connection

WordPress error establishing a database connection

When a beginner starts learning WordPress and develops sites on it, he or she surely encounters many problems. “Error establishing a database connection” is one of the basic errors which one can witness. Experienced WordPress developers don’t get scared with this error rather they enjoy fixing it. On the other hand, beginners don’t take this error maturely and get perplexed easily. Well, after looking for the causes of this error it can be easily fixed. In this post, I will dig a little deeper about this error and come up with the solution that could be implemented smoothly.

What exactly “Error Establishing a Database Connection means”?

First of all, let’s give it an acronym for the term “Error Establishing Database Connection”: EEDC. In order to understand EEDC error, it’s very important to point out that WordPress CMS is built using PHP scripting language and MYSQL database. When we try to open a WordPress website by putting the URL in address bar and hitting enter then it’s the task of PHP to fetch all the required contents from the MYSQL database and display accordingly. However, media files such as images and videos are stored in wp-content folder (File Structure in WordPress). The MYSQL database contains all the crucial information which is needed to create the site. Now, when PHP is not able to connect with MYSQL database because of one or another reason then this EEDC message pops up on the screen. Which is, to put in simple term, PHP is conveying a message: “I couldn’t find the data that is required, so fix the error that I am flashing”?

Possible causes of EEDC Error

  1. Incorrect Database Configuration
  2. Hosting Server Down
  3. Corrupted Database.

Troubleshooting EEDC Error

Incorrect Database Configuration

The configuration of a WordPress website is written in wp-config.php. In this file we need to specify four things for proper connectivity of the site to database which are listed below.

  • Database Name – The name must be correct;
  • Datbase User – Username must be checked;
  • Database User Password – Password must not be wrong;
  • Database Host – Though, localhost is always there in the host name but, sometimes it happens to be different as well. For e.g. localhost:3660 or 127.0.0.1:3360. Make sure it is correct.

Apart from this, if database user has not authorization to perform actions on the mentioned database then also EEDC error appears.

Hosting Server Down

Each WordPress website is hosted on a server. If due to maintenance reasons or by any other reason your server is down then you need to talk to your server provider and ask him to fix the issue as it’s not something you can fix.

Corrupted Database

To find out whether EEDC error is a result of corrupted database or not we must check the wordpress backend i.e. www.site.com/wp-admin. If same error flashes on the screen then database is definitely corrupted. Yes, you read it right but, it can be repaired in three easy and simple steps.

  1. Locate wp-config.php file of your WordPress website and add define ( 'WP_ALLOW_REPAIR' , true); code in the bottom of the file and save your changes. The above process will allow you to repair your WordPress database without going to phpmyadmin.
  2. Now, open www.site.com/wp-admin/maint/repair.php in your browser. You’ll see following screen.
  1. Last step is to choose whether you want to go for “Repair Database” or “Repair and Optimize Database” and let WordPress take care of it from here. After you are done with the repair, delete the code that you added in first step immediately, otherwise hackers might compromise your site.

Did you solve your EEDC error after reading this post? Please share your views in the comments.

Vineet
Vineet
Vineet Kumar Singh is a freelance website developer in Delhi NCR. He has total experience of 3 years in the field of Website Development. Writing blog is one of his passion.
test