Error Establishing a Database Connection is one of the most common errors that frequently happen on WordPress-based sites. The causes for this error can be many; it is a really frustrating error for everyone who wants their site to be up for the users. It could be the result of a number of reasons, which we are going to discuss further in the following section. By the end of this article, you will be able to diagnose the issue and start serving your website normally to your visitors.
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 it for us.
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 started showing 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 name, user, and password, the error could pop up. So, the reason for the error could be several, which we are going to discuss how to fix in detail.
How to Fix Error Establishing a Database Connection Error?
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.php file placed 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 the 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 whether 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 it before the “That’s all, stop editing! Happy blogging” line wp-config.php.
define 'WP_ALLOW_REPAIR', true);
After adding the line, you can visit this URL
http://www.yourwebsite.com/wp-admin/maint/repair.php and repair the database.
Here are some of the most commonly asked questions about the Error establishing a database connection Error.
When this error happens, the very first thing you have to check is your wp-config file. The misconfiguration of the database name, username, and password is the most common reason why this error happens.
Certainly. Incorrect database credentials are one of the most common culprits of this error. Whenever you encounter this issue, you should first check your wp-config.php file and ensure that all the database information is accurate, before doing anything else.
If you are using MySQL, you can use the command
sudo service mysql status to see the status of your MySQL server. It should say “Running” in a green color.
If you suspect a corrupted database, first take a backup, then try to repair it (as mentioned above). If you are not familiar with the database systems, it is better to consult a database developer. Make sure that you trust them or the company with your data.