For a WordPress website owner, the “error establishing a database connection” is very bad news. To many, this problem may look dangerous. When this error shows up, there will be only text and no familiar WordPress site and no design. However, this problem is very common for WordPress users. You will also be pleased to know that you can prevent any permanent damage from happening if this error occurs. 

Know More About Error establishing a database connection:

As the name of the error suggests, it is an error of the database connection. The abilities of WordPress are provided with the help of the technologies of MSQL and PHP.

MySQL

It is a technology of the database used by WordPress for storing the content of the websites. These contents contain elements like your pages and the posts. In addition, it also contains elements that are small, like the color settings, the layout of the widgets, the title of the page,  etc. MySQL primarily stores all the information on the site. 

PHP

This is a language in which the core files of WordPress are written.     

WordPress takes the help of PHP for connecting with the MySQL database. Then, it acquires the required information to display it on the computer screen. In this step, the “error establishing a database connection” error occurs. 

Causes Which Led to This Error in WordPress:

This is caused when WordPress is unable to get the information through the PHP commands in the database. When this happens, WordPress does not know what can it do to fix it. Hence, the “error establishing a database connection” is only displayed on the screen. 

There are some reasons for which this error can take place. So, some of the common reasons behind this problem are as follows:-

1. The login credentials are incorrect

You have to use a particular login and password for accessing WordPress. If you enter any other login and password, then the process of fetching data from the database will not be successful. 

2. The files of WordPress got corrupted

Due to a failed update among files, the WordPress core files can get corrupted. This is caused due to the failed update for the main WordPress software, themes, and plugins. 

3. The database got corrupted

This happens when the database gets messed up internally due to some rogue plugin. The failure of a theme and attack by a hacker can also cause the database to get messed up. 

4. The server of the database is down

The server which is storing your files of the website may be on another machine than the WordPress database. And, this server of the database can be down for any reason. Then, this problem of error establishing a database connection” will show up.

5. Traffic

Sometimes, when one of your posts goes viral, then the traffic on your site increases. This spike in the traffic can make your server unresponsive. 

Procedure to Resolve “Error Establishing a Database Connection”:

Now that you are aware of the reasons behind the occurrence of this “error establishing a database connection”, let us check out the solutions for eliminating this error:-

Procedure 1. Contact the Web Host Provider

If you are facing this problem, then there is a chance that the problem is at the end of the web host. Most of the hosts provide the option of Live Chat. You can use this option and tell them in detail regarding the problem of “error establishing a database connection”. 

When you let them know about your problem, they will either tell you how you can solve the problem, or they could even solve it for you. Whatever might be the case, they will let you know whether the server is facing any serious problem or not. If you find that the problem is not on their end, then the problem has to be on your end. 

2. Examine your Theme and Plugin Files for any Sign of Corruption

Due to some misfortunate events, the WordPress files can get corrupted. This can happen, maybe when you have hand-edited some files, hooked your site to an external server, or updated a theme or a plugin. If you have done any of these steps, then you will find your problem. 

So, let us see what you can do to fix this problem. You have to follow the given steps to get rid of this problem:-

First Step

You have to connect to the host through FTP. For connecting, you will require a login and a password for the account in the FTP. However, if you have forgotten this information, you can search through your earlier emails. You can also ask for it in the live chat support. 

After you have acquired this information, log in to the server and then you have to navigate to the root folder of WordPress. The name of this folder is normally given “WWW” or “public_html”. You can also be inside this folder when you have made a connection with the FTP. If you see folders with the name of “wp-admin” and “wp-content”, then you have to understand that you are in the root folder of WordPress. 

Second Step

Now, you have to enter “wp-content”. After that, you have to change the name of the folder of the “plugins”. Then, you can go back to your site and check if the “error establishing a database connection” has been solved or not. 

However, if your problem is caused due to something other reason, then you have to go to the FTP folder and change the name of each of the plugins. The easiest way to rename these folders is by adding a “_” at the end. When you are changing the names, you have to keep coming back to the website to see if the error is being fixed. 

You will be able to narrow it down to the particular plugin. After that, you can delete it, or you can find a way to solve it.   

3. Fixing the Corrupted Database

The database of WordPress is a very complicated thing. There are many small cogs that work in a unified manner to run this without any trouble. However, sometimes these things can go out of place and then the “error establishing a database connection” occurs. 

  1. First of all, you have to examine your dashboard of WordPress. You can do it with the help of this command

YOURSELF.com/wp-admin

  1. After that, you have to notice what WordPress is prompting you to do. You should follow everything it will tell you to do. In the latest version WordPress, the problem-solving solutions have been increased. 

However, if you see the message of “One or more database tables are unavailable”, then it indicates that the database needs to be repaired. 

Conclusion

The three solutions discussed above are the most effective solutions for resolving “error establishing a database connection”. If you know what the reason for your problem is, then you can opt for the appropriate method. However, if the reason is unknown, you can try the solutions one by one. One of the solutions will definitely solve your problem.