Trying to open your WordPress blog but you are getting an error stating “Error Establishing a Database Connection”,This is what I got on one of my WordPress blog.
Recently I switched Hosting for one of my WordPress Blog, Earlier it was on Shared Hosting and now I decided to move it to a Unmanaged Virtual Private Server, Everything went smoothly and the blog was working perfectly but soon my WordPress blog started showing “Error Establishing a Database Connection”, and I started finding for the solution but none of them worked.
The problem for the error will not be the same for everyone,therefore I’ll be posting all the possible solutions.
How to Fix Error Establishing a Database Connection In WordPress
Reason for The error
The reason is that WordPress failed to connect to your Database and can’t fetch the data from database, whenever a user requests for a page. WordPress sends a requests and get response from the database. There can be various reasons for this and we have to find out and fix it.
It’s unlikely that this can be the reasons,but still check it that all the below value are correct and no one have altered them.
Normally the value of DB_HOST should be localhost but some users have said that changing the value to the below one had worked for them.
Changing the DB host may solve the issue as it had worked for most of the people and hope you will get Rid of “Error Establishing a Database Connection”.
2.Database got corrupted
May be your WordPress Database is corrupted and that’s why you are getting the error,in that case you will have to repair your database,add the below code in your wp-config.php file and visit the given URL and repair the database.
Note:Remove the Code after repairing the Database.
Visit the URL -http://www.yoursite.com/wp-admin/maint/repair.php
3.In my case none of the above were reason,actually it was memory problem in my case and increasing the RAM of my server solved the issue as my server didn’t had enough memory to handle the DB queries WordPress was generating.
4.Check if Your SQL server is working,You can contact your hosting provider to check the same.
5.If you are on shared Hosting,check if your Hosting can handle that much of traffic if you are getting too much traffic.
6.It’s not necessary that if something had worked for me will also work for you,If you are getting this error and none of the above solution have worked for you, check the recent changes you have made in your WordPress blog and check that all of them are correct and you haven’t done something wrong and try to change it to the previous value and check if it works.