Web Analytics

For a person who owns a WordPress website or manages one, a simple text-based error such as “Error establishing a database connection” can ruin your entire day.

Although there are plenty of errors that you might come across in a lifetime, this one, in particular, is capable of messing with your brain.

Even just looking at the error screen, which consists of significant sized Error in bold with no images or any design, you might start to panic.

Well, that is the reason why we decided to save your day with our brief guide on How to fix Error establishing a database connection in WordPress.

How to Fix Error Establishing a Database Connection in WordPress

It is essential to understand the Error before we dive deep into the possible causes and fixes. Once you already have the idea of the problem, trying various fixes becomes a whole lot easier.

Understanding the Error

After reading the Error itself, you might have already guessed that its something related to the databases. Well, that’s undoubtedly true. If you’re not aware, WordPress runs on two primary technology named MySQL and PHP.

The former is the language used for handling databases, while the latter is a programming language used for core features. All the core WordPress files are written in the PHP language.

MySQL, on the other hand, is used to store your website’s content and information (even the smallest one).

When WordPress is unable to connect with MySQL (your database) using the PHP language files, then this particular Error comes into play.

Well, there could be numerous reasons for this disconnection between the two primary technologies. We are listing a few common ones below.

  • Incorrect login credentials: If you have recently changed your database password, then this Error can be a result of that. There will be a need to update the login credentials in the PHP files.
  • Corrupted Database: Your database can be easily damaged if you have installed a poor-coded plugin. There are many reasons for a corrupt database.
  • Limited Bandwidth: If your website is experiencing heavy traffic beyond the server limit, then you can come across with this Error.
  • Web hosting: Well, there is a decent chance that the culprit to this problem is your web hosting provider itself.

Steps to Fix Error Establishing a Database Connection in WordPress

Enough talk! Let’s talk about the number of fixes that you can try to fix this problem once and for all. Follow the below steps one by one until you find the resolution to the issue. It is recommended to take a complete backup of your website using FTP clients such as FileZilla before proceeding further.

Step 1: Contact Web Hosting Provider

The first order of the business is to get in touch with the web hosting provider itself. First of all, it is highly likely that the problem is due to the server issue from the provider’s end.

Even if it’s not, the customer support will be able to help out in a much better and more natural way. You can ask whether the server is down or your website is experiencing high traffic spikes or not.

If the issue is not from the web hosting provider’s end, the customer support will let you know the cause and might even fix it up for you.

Furthermore, you can also get the information on your database, such as if it is corrupted or not. Well, if your hosting provider support is not up to the mark, you can proceed further to step 2.

Step 2: Check for Corrupted Plugins or Theme Files

As mentioned earlier, there is a pretty decent chance that a particular plugin or theme is interfering with the database connection. This interference generally happens when a plugin or theme files get corrupted for some reason.

Since your website is already down, you will not be able to access the “/wp-admin” page. To access the installed plugins or themes, you will need an FTP client such as FileZilla.

Using this free software, connect to your host by entering the FTP username and password. If you don’t have that, we will recommend getting in touch with support.

  • Once you’re connected to your host, head over to the WordPress root folder, it’s usually called “public_html” or “www.” On the contrary, you might have already been in the root folder. Look for the “wp-content” and “wp-admin” folders. If you’re able to find them, then you’re already in the root folder.
  • Now, open the “wp-content” folder and rename the plugins folder to anything (or add an underscore in the end).
  • Once that done, try re-opening your website. If it opens, then you have found the culprit here. Now you know that a particular plugin is the root cause of the Error.

Using the same renaming method, you can rule out one particular plugin. Similarly, you can follow the same technique for the themes folder if the plugin root directory is not the culprit.

Step 3: Repair your Database

If the above step does not work out for you, then we will recommend repairing the database just in case. To do that, all you have to do is follow the guide given below. Repairing a WordPress database is relatively simple, and here’s what you have to do.

  • Connect to your host address using the FTP client. Head over to the root folder and look for the “wp-config.php” file.
  • Download the file and open it in the Notepad. At the end of the file, add the below text. You should add the text before the “That’s all, stop editing.”
  • define('WP_ALLOW_REPAIR', true);
  • Upload the file back to the same location from which you downloaded the first time.
  • Now, head over to the following address to start the repairing process.
  • YOURSITE.com/wp-admin/maint/repair.php
  • You should now be able to see a repair dialog box consisting of two options, namely “Repair Database” and “Repair and Optimize Database.” You can select any one of them to initiate the repair process.
  • Once the repair is complete, you will have to upload the original “wp-config.php” file to the same location.

Step 4: Recheck the Login Credentials

Another thing that you can do to fix the problem is rechecking or updating the login credentials for your database. Like the previous step, you will have to download the “wp-config.php” file. Look for commands mentioned below using the find feature in the Notepad.

define('DB_NAME', 'some_db');
define('DB_USER', 'some_username');
define('DB_PASSWORD', 'some_pass');
define('DB_HOST', 'localhost');

If you don’t have the login credentials, then you can get in touch with the hosting provider to receive the credentials information. Replace the information and overwrite the file to the original location.

Step 5: Fix the WordPress Core Files

All the steps mentioned above most commonly fix the database error in WordPress. If it doesn’t, we will recommend re-uploading the core WordPress files. Here is how you can do that.

  • Download the latest version of WordPress from the link and unpack it.
  • Look for the “wp-content” in the unpacked folder and remove it.
  • Once that done, upload the entire files to your root directory using the FTP client.

Recheck your website and see if the problem is fixed or not. If not, then get in touch with the hosting provider again and ask for them to fix the issue for you.

Author