One of the common issues that you might see in your WordPress website is where you see “Error Establishing Database Connection”. It’s a pretty common error and it’s seen on a completely blank page with only one line.
When you see the error with just one line, it becomes harder to solve. That’s what you might be thinking. However, in reality, it’s super easy and simple to solve the error. We will see how you can solve this error in no time.
We will see the main cause of this error and then we will move on to the solution where we will see how you can solve it. We will see a couple of ways to solve it (Not just one).
Overview of Error Establishing Database Connection
When it comes to a database error, it’s pretty simple to understand what it means.
Here, the error says Error Establishing Database Connection. It simply means that the server can’t connect with the database. There might be millions of reasons for this.
In most cases, it’s because of the database details. Don’t worry, we will see all of them one by one and see how you can solve them with ease.
The error is shown in a single black line. There are no other ways that error is seen. So, whenever you see the error, it will clearly say that Error Establishing Database Connection.
Now, we will how to fix Error Establishing Database Connection error.
How to fix Error Establishing Database Connection?
Before we get into the steps, make sure you have taken the complete database and file backup. In simpler words, you need to have a current backup of your website. In case, something goes wrong, we can easily restore it if we have a backup. So, it’s important to have a backup when you are troubleshooting an error.
The first and the easiest way to solve it is to wait for a couple of seconds and refresh the page. Sometimes, when you are updating the theme/plugin or WordPress version then it might show Error Establishing Database Connection.
Even if you didn’t update anything, it’s always better to wait because there might be some automatic updates going on. It won’t take long. It hardly takes a minute. So, you can just refresh the homepage after a couple of seconds to see if it has solved the issue or not. If it hasn’t solved the issue, you can continue to the steps and try the mentioned methods.
Database Details and Account
This problem usually happens when you have migrated the website or transferred the website to some other host. Also, if you have installed WordPress manually and you’re seeing this error then you need to check this out. Other people can directly go to the next steps.
One of the most common reasons for this error is the database details. Before we talk about the database details, let’s talk about the database account.
You need to create a database account and give all the permissions to the user.
Open your cPanel and head over to the MySQL database, there will be an option for the users. Make sure you have allocated all the permissions to the users. If you haven’t done it already, you need to make sure that you create a MySQL database and give all the permissions to the person.
Once you do all that, you need to come back to the main point that is database details. You need to make sure that the database details are entered correctly. To check that, you can first open the file manager and then head over to the WordPress directory.
In most cases, you will see the folder named with your website or you can head over to public_html. Now, when you are inside it, you can open the wp-config.php file.
Right-click on it and then select the code edit option from the given details. It will open the code of the file.
Now when you see the code, you will have to see that the database name, database username, and database password are correct or not. If any of these isn’t correct then fix it and try again.
Rollback the Changes
One of the best ways to solve any error in WordPress is to roll back the changes that you recently made. If you recently installed a plugin, then you need to deactivate it.
If you don’t have the access to wp-admin then how will do it?
Well, the answer is simple. Open your file manager and open the WordPress directory. Head over to the wp-content folder. When you go there, you will have to select the plugins folder. Inside the plugin folder, find the plugin that you want to deactivate. Once you find it, just rename the plugin and that’s it.
When you rename the plugin, the plugin will be deactivated. Now, you can try visiting the website again. The same applies to themes too.
If it is still not working, you can move back and change the name of the entire folder. Change the name of the folder from plugin to plugin1 or anything you want. This will deactivate all the plugins. Now, try to visit the website again.
If it doesn’t work, you can do the same thing with the themes.
Make sure you change the names back to the original one.
When you change the name back and the website again steps working, you need to check all the plugins one by one to find out which one is at fault.
This is the easiest yet time-consuming way to do it. Therefore, you can surely try it. Sometimes, when the plugin misbehaves, it might get corrupted. So, this error is seen.
However, following the given steps will surely solve the issue. Therefore, you can try the given things and if it doesn’t work then your database might be corrupted. We will see how you can fix it too.
Fix Corrupted Database
We are not yet sure that the database is corrupted. So, we will see whether the database is corrupted or not in an easy way.
Try to open example.com/wp-admin which is your admin dashboard. If you see the same error, it means that your database is not corrupted. However, if you see some other error that says check your database then there are good chances that your database is corrupted.
First, you need to check that your database is present or not. So, head over to the MySQL database from the cPanel and then see whether the database is there or not.
If it’s there, you need to repair it. You can add the following line in the Wp-config.php file. See the above steps to know the path.
Now, you can open the following link.
Replace example.com with your website. Now, it will ask to repair the database. Just click on repair and you are done. Your process will be completed in a couple of seconds. It might take minutes depending on the files.
Replace the Core Files
Your last or we should say the second last option would be to replace the core files of your WordPress.
Download the WordPress zip file from the official website. Extract it and delete the wp-content folder from it. Now, you need to open the wp-config.php file and then change the database name, username, and password.
Once you make the changes, you can upload and replace all these files with the original files in your webserver.
Make sure you take a complete backup of your website before you perform this action.
After you replace all the files (except the wp-content folder and after changing wp-config.php), you can try loading the website again. It will surely work. If it’s still not working, we have got one last solution.
Contact the Hosting Provider
The last option will be to contact the hosting provider. The hosting provider will surely help you out. Most people don’t contact them thinking they won’t help or they are just fearing. However, the support team will surely help you. It doesn’t matter whether it’s a technical error or some other, they will surely help you.
They can even tell you why you are seeing this error. So, even if they don’t fix it, they will tell you what’s wrong and which files you need to change to fix the Error Establishing Database Connection error in WordPress.
To conclude, these are some of the best ways to fix the Error Establishing Database Connection error in WordPress.
You can try all of them one by one in sequence. We have given the list by keeping in mind the common reasons. In simpler words, most people face errors because of incorrect details and the least number of people face this error because of the core files corruption. So, you can try applying all the methods one by one. Again, make sure you have a backup before you begin.