How To Fix Error Establishing A Database Connection In WordPress?

Error Establishing a Database Connection– This error isn’t less than a minor heart-attack to WordPress users. It’s a terrifying situation, and you’re like helpless for a moment.

So what basically I want to tell you is that WordPress is the biggest blogging platform, and as a developer or webmaster you have to be ready to face such problems because the longer you work with WordPress, the more are the chances to encounter the dreaded situations like WordPress error establishing a database connection.

This database connection error is one of the scary errors that cause your site to temporarily be inaccessible. The error doesn’t reveal what went wrong and you start scratching your head.

In today’s post, we will go into detail about this WordPress error establishing a database connection error. So if you’ve ever encountered this error or trying to find a solution for it then don’t worry, because I will show you how to fix this error in easy steps.

Here we go….

Don’t Miss: What is WordPress? Why Is It Free and Should You Use WordPress?

What is the Error Establishing a Database Connection Error?

Before we discuss how to resolve EEDC error, we first need to understand what this error actually means?

Do you know the two fundamental components of WordPress?

They are PHP and MYSQL. You might have seen files like index.php, sidebar.php, header.Php, etc in your WordPress dashboard. These are PHP files. PHP is responsible for all the functions on your WordPress site like posting comments, retrieving posts, and pages, etc.

On the other hand, MYSQL is responsible for data storage. The posts and pages you publish are saved in a database that WordPress needs to reference each time it serves a web page.

So what happens for some reason the PHP code is unable to connect to MySQL database to retrieve the information it needs to load the page. In short, WordPress cannot find the database and therefore, error establishing a database connection appears on your screen.

WordPress not only saves the posts and pages. It also stores a lot of other information in its database like user data, your theme, widgets settings, plug-ins data, and so on. If WordPress can’t access any of the information within its database, then there are 100% chances that your website will not be loaded.

What is the Cause of WordPress Error Establishing a Database Connection Error?

So you people are much aware of the error, and now many of you might be expecting the reasons due to which this terrible error occurs, right?

There are so many reasons below (including but not limited to) which could cause errors in database connectivity:

    • Incorrect Database Details

In case if you have recently made changes to your database credentials like username, password, host, etc then you won’t be able to access your database with the old ones. If you try to put wrong credentials then, your website will be blocked from accessing the database.

So your prime task is to confirm that you are entering the correct login credentials.

    • Corrupt Database Files

Another reason for Error Establishing a Database Connection error is the corrupt database files, which can be caused by several issues like installing an incompatible or bad plug-in, add-ons, themes, etc or by making some changes in your php files manually.

  • Overloaded Database Server

Due to heavy traffic on your website the server that hosts your database may temporarily be down.

Now we are heading to the section where we will try fixing that error and getting your site back to its normal form.

How to Fix Error Establishing a DB Connection Issue?

I have already mentioned some of the reasons that may cause your site down. Now let’s take a look at each of the issues and see what we can do to fix things.

  1. Wrong Database Credentials

To connect to its database, WordPress needs correct information about-

  • Database host
  • Database username
  • Database password
  • Database name

To check whether the information is accurate, open your wp-config.php file and look for the following lines of code:

Error Establishing A Database Connection -Change Login Credentials

You can see the second pair of parentheses like ‘database_name’, ‘database_user’, ‘database_password’, ‘localhost’. These details are specific to your website and host.

Note: You can open the wp-config file using an appropriate FTP client because there may be a case where you won’t be able to open your WordPress dashboard to access files.

The reason why you are asked to double-check your DB login credentials is that you may have changed your host recently and the correct login details might have not updated. In that case, you can even go back and fill out this information manually.

To modify the details, download the wp-config file locally on your system and edit the file using a text editor. You only need to change the values in the second set of parentheses to the correct values. Once you make all the changes re-upload the configuration file located in the WordPress root directory.

Now the question is how you would get the information about these four key pieces? The easy way is to contact your host provider and ask them directly. You will get the solution instantly.

There are high chances that your site will be up and running normally, but if you’re still getting the same error, then it’s time to look into another issue.

  1. Corrupted Files

If updating database credentials don’t work, you can try to fix corrupted files in WordPress. Sometimes the error could be because of corrupted WordPress files, and what step you must take to solve this error will be discussed in this section.

We all know how important and crucial is the WordPress files. A single mistake can wipe away your entire site. So before you proceeds, backup all of your data either manually or by using a plug-in.

Now what you need are the new WordPress files to replace the old corrupted files that are causing problems. Well, the exact reason why replacing files can work is still a mystery, but it works in many cases.

Follow the steps below to get it done:

  • Download a fresh version of the WordPress CMS from WordPress.org.
  • Unzip the package on your computer.
  • Now from the unzipped folder delete both the config.php file and the wp-content folder. This has to be done because this will ensure you don’t overwrite the wp-config.php file or the wp-content folder which contains themes, plug-ins, and media- the base of your website.
  • After deleting both file and folder, upload the rest of the files into your WordPress root folder using the File Manager or an FTP client. It may fix all the corrupted files, and your website will run smoothly.
  1. Corrupted Database

If above two methods doesn’t work, you need to check your WordPress database. To do this, go to yoursite.com/wp-admin/. Here yoursite.com is the domain name of your site. If your database is corrupted, you will see an error message telling you that some database tables cannot be found.

Don’t worry, here’s the solution. Just download wp-config.php file from the root directory of your WordPress install (mentioned above) and add the following line:

Error Establishing A Database Connection

Once you’re done, upload the wp-config.php file again in the root directory. Now you can access a particular database repair page on your site by going to http://yoursite.com/wp-admin/maint/repair.php.

You can see the screen (shown below) displaying two options which are ‘Repair Database’ and ‘Repair and optimize Database.’

WordPress Error Establishing A Database Connection- Repair Database

Now you can choose either option, but I’d recommend choosing only to repair the database.

Once your database is repaired, do not forget to delete the code you added to your wp-config.php file as the repair page will remain public as long as the code exists in the file, and hackers can easily access your database.

By following above steps, you’ll be able to fix the EEDC error.

Final Words

You will now have an idea that the exact cause of the WordPress error establishing a database connection error can be one of many. In my case, it was a typo error in footer.php file. I was trying to make some changes in coding but experienced something very scary.

If you’re having the same issue, follow the above methods to get your site up and running. Please share your experience with us, like what caused it, how did you resolve it? It may provide other alternatives to solve the error.

Leave a Reply