How to Fix the Error Establishing a Database Connection in WordPress

No matter how hard we try to avoid it, there comes a time when we come across the dreaded error establishing a database connection. It certainly is a bad day for WordPress website owners.

The error message looks very serious since it does not have any design or WordPress site element. Instead, it is just plain text. If you experience the issue, you must not panic.

Now, you might feel a bit scared. However, there is nothing to worry about as the problem can be resolved, and permanent damage is preventable. The fact is that it is quite common for the error to occur. This post will help you better understand the problem and how you can resolve it.

Understanding the Problem

The error itself is self-explanatory. It is an error that is caused by an inability to establish a database connection.

To better understand it, you must note that WordPress makes use of two different pieces of technology to provide you with the ultimate experience. It includes PHP and MySQL, as mentioned below.

  • PHP: It is the programming language that powers WordPress. All the core files on WordPress are written using PHP.
  • MySQL: It is a database technology that helps store the website content, including pages, posts, and also smaller elements like the color settings, widgets, title, and more. In its essence, MySQL provides a database for storing every bit of information.

To put the two together, WordPress makes use of PHP commands. It helps connect the two to get the required information to display on the screen. Now, this is where the error occurs as WordPress is unable to access the information from the database through PHP commands.

The error occurs because WordPress does not know what it should do next. The following reasons might be to blame for the error.

  • Corrupted WordPress files
  • Incorrect login credentials
  • Corrupted database
  • The server of the database is down
  • Too much traffic

How Can You Fix the Error Establishing A Database Connection?

Now that you have a better understanding of the error itself, you will have an easier time understanding how to fix it. The following steps will help get your WordPress running in no time.

Get a Hold of Your Web Host Provider

The first thing that you need to do is contact your web host for support. If your website has not been working for a while now, the chances are that there is a fault on the web host’s end.

Most quality hosts today offer prompt support and WordPress optimization. You should be able to discuss your problem through live chat, and they will get back to you immediately. Let the support team know about the error you are experiencing.

The support team will either tell you about the exact cause or fix it. They will inform you about the database and if there is any suspicious activity.

Generally, the team will resolve the problem as long as it is on their end. However, if it is on your end and they do not want to help you, the following step will prove useful.

Click If the Theme or Plug-In Files Have Not Been Corrupted

Misfortunate events can occur which would corrupt your WordPress files. For example, you might have updated a theme or plug-in, which could have collapsed the entire thing. It is also possible that you might have hooked up the site to an external source or hand-edited some of your files.

If you think that any of the above is to blame, you already know what went wrong. However, if you have not done any of that, you can simply skip this step. Now, here is what you need to do.

  • Firstly, connect with the host through FTP. Use a free tool such as FileZilla to do this. To connect, you must enter your login details. If you do not remember the details, you can always search for them from the initial emails you received. Otherwise, live chat support will help you out.
  • Once you have connected with the server, you must open the WordPress root folder. It will appear as “www” or “public_html.” You might already be in it.
  • As a rule of thumb, if you enter sub-folders such as “WP-Admin” and “WP-Content,” you have accessed the WordPress root.
  • After you enter “WP-Content,” you need to rename the “Plug-Ins” folder to anything else as long as it is not “Plug-Ins.”
  • Now, head back to the site to check if the error still appears.
  • If it does not, it means that the error was caused by a plug-in. If this is the case, go to FTP and rename the folder to “Plug-Ins.” Enter the folder and change the folder names of each plug-in, one at a time. You can add an underscore towards the end.
  • Keep visiting the site to check if the error vanishes or gets triggered. By doing this, you get to narrow down the problem to a specific plug-in. You can either delete the plug-in or check online to find a solution.
  • If the error does not disappear after renaming the folder, you need to proceed with the same process on the themes folder.
  • However, if it does not help, something else is causing the error.

Restore the Default WordPress Files

There are a variety of reasons behind the error, including the core WordPress files getting corrupted. It is also possible that someone tried to hack your site, or you might have edited some of the files by accident.

Regardless of the cause, all you need to do is download WordPress again from WordPress. Copy the clean version over the one you are using right now. Download the latest package for your desktop through here.

Now, make sure to browse through the unpacked archive and delete your “WP-Content” folder. After this, you need to connect the site with FTP and head over to the main WordPress root, where you will upload the new files. Thus, all the previous files would be overwritten.

Once the upload is complete, you can visit the website again to see if the effect is gone. Remember, this should be your last resort.

Fix the Error Establishing a Database Connection in WordPress

Fixing the error establishing a database connection in WordPress is not as difficult as it might seem. As a recap, you will need to contact your host or check to see if a plug-in or theme is corrupt. Only as a last resort should you re-download WordPress. We hope you find our guide helpful.