In the Morning of a lovely Sunday, we come across “Error Establishing a Database Connection” issue on all of our WordPress websites. Additionally, we also found that cPanel was also not working well. The Problem gets solved in an hour with the support of our reliable hosting provider and today I am sharing methods to fix this error. But I believe in understanding the problem before trying to solve it so before providing the direct solution I want to share the information about this error.
Is your WordPress website inaccessible due to this error? Stay with us and here we will show you how to easily fix the error establishing a database connection in WordPress.
What is “Error Establishing a Database Connection”?
‘Error establishing a database connection’ is one of the most common WordPress errors and the error occurs when WordPress failed to connect with the database. Due to it, your WordPress website will stay inaccessible to the users. There can be a number of reasons that can affect the connection between WordPress and database, and due to the complexity, this error is a bit difficult for beginners to troubleshoot.
Recommended: Best SEO Tools For Beginners: Get a Quick Start
What is Causing Error establishing a database connection?
There are 5 well-known reasons that can cause ‘Error establishing a database connection’ and the same are explained below.
Incorrect login credentials
If the login and password to access the database have been changed, then the WordPress CMS will be not able to fetch any data from the database and that’s why this error occurs.
Corrupted WordPress files
Failed updates of the plugins, themes, WordPress software and even hacking and malware attack can corrupt core files of WordPress which can cause this error on your WordPress website.
Corrupted database
Themes, Plugins, hacker’s attack, manually messing with the database internally, and many more activities can corrupt the database and then WordPress will not able to connect with the corrupted database and this failed attempt to connect with the database can cause this error.
Too much traffic
Due to the high amount of traffic, your database might be unresponsive and when it happens, the server can fail to handle part of that traffic and then this error can occur.
The database server is down
Due to maintenance or any other internal reason, the webserver can go down. Basically, WordPress files are stored on a web server and web server and database server runs on different machines. and sometimes the separate database server can simply be down and causing this error.
Also Check:How AI is Going to Affect Content SEO Strategies in 2025?
How to Fix Error establishing a database connection?
After a quick Introduction and all the possible reasons that are causing this error Let’s take a look at how to fix error establishing database connection issue in WordPress. You are engraving the easiest one at first and in most of the cases, it will fix the problem for you quickly.
1. Contact with Your Web Host Provider
If your WordPress website was working fine a few minutes before then, maybe something is not working from the hosting provider’s end and contacting with support team is the easiest and efficient way to solve errors.
Almost all reputed hosting provider features technical team these days and they can help you in even the worst errors. Just contact them with live chat, call, or email or through any other mode available and inform them that you are facing an “error establishing a database connection” and ask them if the database server is running with no problems and if there is any spike in activity or traffic on the server right now.
In most of the cases, they will tell you the reason for the problem and if it is from their side then they will solve it for you. And that’s why it is the easiest method to solve this error. But in case if the problem is not from their side then you have to solve it manually by following some a bit complex methods.
2. Find and disable Corrupted Plugin or Theme Files
A recently installed/ updated plugin or theme can be also the culprit and to find them and disable them you have to use FTP, it is because FTP is the best way to solve it and in most of the cases with this error the cPanel also start to behave weird.
- First of all, connect to your host via FTP using the tool FileZilla.
- If the WordPress root folder opens up for the specific domain then it is fine, otherwise, after successful connection navigates to the WordPress root folder, in my case it was public_html/weobserved.com. basically this folder will have 3 subfolders “wp-content”, “wp-admin”, and “wp-admin”.
- Now go to “wp-content” and rename the “plugins” folder to something else, ex. plugin, plugins1, plugin back, means anything.
- Now, in the new tab open your site and see if the error is still there. if not then we figured it out that one of the plugins was causing the error.
- In this case, rename the folder back to “plugins”.
- Then Go into it, and change the subfolder names of the individual plugins, one by one. and after renaming each folder open your website and check which plugin is causing the error.
- After finding the one plugin that is causing this error, delete it. and enjoy your website.
- Now, in case if after changing the name of folder “plugins” to something else, and the same error is still there then. find the folder “themes” in wp-content and follow the exact same process we followed in steps 4.1,4.2. and 4.3.
- If the error is still there then rename both folders back to “plugins” and “themes” and move to the next method because the error is caused by something else.
Also Check: How to check Bounce Rate in Google Analytics 4?
3. Fix Corrupted Database
If the above method failed then we have to fix Corrupted Database or if I say more precisely then we have to reconnect the database. WordPress is a great CMS platform and in the past few years it is getting smart and mature so it can handle some of the issues itself but it needs some help.
- First of all, go to your WordPress dashboard – xyz.com/wp-admin #here, replace xyz.com with your domain.
- If the same error: “Error establishing a database connection” appears then skip this step. But if a new error appears like “Can’t select database” or “One or more database tables are unavailable”, then this method is for you. You need to repair the database.
- Connect to your host via FTP using the tool FileZilla
- If the WordPress root folder opens up for the specific domain then it is good, otherwise, after successful connection navigates to the WordPress root folder, in my case it was public_html/weobserved.com.
- In the WordPress root folder, find and download the “wp-config.php” file to your desktop.
- Open it with text editor or Notepad or even in Online Notepad.
- Then add one line of code at the end: define(‘WP_ALLOW_REPAIR’, true);
- Now save it and upload the file to the direction and overwrite the previous one.
- Now, open xyz.com/wp-admin/maint/repair.php #here, replace xyz.com with your domain. You will see something like this:
- Now either click on the Repair Database button or Repair and optimize Database button, both will work but I will suggest you go with the second one.
- When the automatic repair finishes, open your website and see if the error is still there.
- If there is no error then Great we solved it but before doing anything else we have to revert the“wp-config.php” file to its previous state. You can do that by simply downloading the file through FTP and removing the code you had added earlier (step 7), then save it and reupload it.
But if the error is still there then move to the next method.
4. Check and use Correct Database Connection Credentials
WordPress uses a specific database username and password to connect to the database and it is not the same you are using to access your website’s dashboard. These database username and password details don’t change on their own but if it happens then we need to fix it and steps are below.
- Connect to your host via FTP
- In the WordPress root folder, find and download the “wp-config.php” file to your desktop.
- Open it with text editor or Notepad or even in Online Notepad. You will find something like this:
- Now copy these lines and start a live chat with your Hosting provider representative.
- Paste these lines and ask them if all the details are correct.
- The representative will check them, and they will tell you if something needs to be changed. Do changes as per their feedback.
- Open the “wp-config.php” file and replace the old ones with the updated details, save and re-upload the file to the server via FTP and open your website again.
- If it works then great otherwise move to the next method.
5. Restore the default core WordPress Files
If everything from above failed to fix Error Establishing a Database Connection in WordPress then one more thing you can do to fix the error, you just have to restore the default core WordPress Files. You can do that by following the steps given below.
- Connect to your host via FTP
- Find and download the “wp-config.php” file to your desktop and keep it safe. Verify the database username and password with the help of Hosting provider representative. And keep them safe.
- Now Go here, and download the latest WordPress zip package to your desktop. Extract it, open it and delete the “wp-content” folder.
- After it, open the wp-config.php you downloaded in step 2 and copy and paste the database Username and password you verified in step 2.
- Save it.
- Now connect to your site via FTP, in the WordPress root upload all new WordPress files. Overwrite all the previous files.
- After doing that, Open your website and I hope that the error will not appear.
These are the five proven methods we use to solve Error Establishing a Database Connection in WordPress, in most of the cases the first method is enough but if you really have a bad day then you have to try these methods one by one until the error get solved. You can also take help of hosting provider reparative and some trustworthy web developers or some experts. Meanwhile, there are also some measurements you can follow to avoid this particular error in the future.
Must Check: Benefits of Google Business Profile to Small Businesses
How To Avoid This Error In the Future?
100% fail-proof sites are just elusive thoughts but there are three things you can do to keep your WordPress website at least 80% safe:
Choose Quality hosting
Don’t go with cheap yearly plans they will just give you storage space which can be failed anytime. Spend some time, do some research and choose a hosting provider that can be a optimize platform for your WordPress website. In this way, you will get knowledgeable support and fast help which result in avoiding many common WordPress problems. As per my personal experience of running around 11 websites, I will suggest you choose Hostgator because in our 5 years of the long journey they never disappointed us.
Keep backups
You can either install a simple plugin like UpdraftPlus or take backup through the Cpanel and you are ready to go. However, UpdraftPlus works automatically so choosing it will be a wise decision. You should always have a working backup that can be restored if something fails. one extra tip, always keeps backup of wp-content folder.
Don’t try extraordinary things
Yeah, I know if help to learn and explore new things but I will suggest you to not do anything extraordinary in WordPress core files, otherwise your minor changes can cause you and your website a lot of trouble. So, before trying anything first do some research, gather some information, analyse the risks and get ready with the troubleshooting ideas.
Must Read: Accuracy of AI detector Tools: 3 Best Tools, 4 Tests, Check Results
We hope this 2000+ words guide will help you to fix error establishing a database connection in WordPress. If you’re having some tough time with these errors or even with SEO and websites feel free to reach out to us. Also, share your thought, tips and suggestions using the comment section. Thank You, keep visiting and have a nice day.
If you liked this article, then please follow us on Twitter, Instagram and Facebook.