Error Establishing a Database Connection is one of the most common error for WordPress based sites. The causes for this error are so many; it is a really frustrating error for everyone who wants their site to be up for the users. It can be caused by a number of reasons which we are going to discuss further in the following section.
Reasons for Error Establishing a Database Connection
Personally, we experienced this error for so many reasons. We have plenty of sites running on different web hosts. We have seen this error in Godaddy Managed WordPress hosting regularly. To fix this error, we called the Godaddy customer support guy, and they fixed on behalf of me. It is just to ensure that, if you are a GoDaddy customer, you can get the error fixed by them just by contacting their support. The thing won’t be different for other hosts as well. So, you are good to go if you do not want to know the roots of the Error Establishing a Database Connection error on WordPress and just want to get the problem resolved.
This error is really frustrating when you don’t have CPanel. In Siteground, I faced this error due to the insufficient nodes available in hosting. Whenever I try to publish a new article, the server stopped responding and shown this error. I contacted their support team to fix the error, they suggested upgrading the plan with more nodes and RAM. In KnowHost VPS 1 plan, I faced this problem again, an increase in RAM fixed the issue. In some rare cases, if you do not set up the wp-config file correctly by pointing it to the correct database with the exact same database user and password, the error could popup. So, the reason for the error could be several, which we are going to list below.
How to fix it?
So, you know the reasons for the error, now you have to know how to fix them. Here we are going to list several methods for fixing the database Error Establishing a Database connection problem on your WordPress website.
Check your wp-config.php
Make sure that you have provided the correct database name and password as well as the correct database user in your wp-config file places in your home directory. If you enter any one of them wrong, WordPress won’t be able to communicate with the database returning this error. So, the first thing you have to check is your wp-config.php and make sure that everything is entered correctly.
Check your Resources
To fix “Error Establishing a Database Connection,” you have to check the resources available on your side. If you are the admin of the site, first check the functionality of the site in both front and backend. If some of the functions are getting broken or if the page takes too long to respond, it is possible that your server is running out of resources and you probably have to upgrade it. In this case, you can check what specific part of the resources is running out. Identify it is CPU, RAM, or Disk and upgrade those resources accordingly.
Try a Database Repair
If you are getting an error on the wp-admin “One or more database tables are unavailable” means your database needs to be repaired. You can do the repair by adding the following line just add before the “That’s all, stop editing! Happy blogging” line wp-config.php.
define 'WP_ALLOW_REPAIR', true);
After adding the line, you can see the settings page and repair the database.