Error Establishing a Database Connection WordPress Localhost is a common problem. This problem is faced by many popular blogs also including us. We also faced the Error Establishing a Database Connection WordPress Localhost in past. Our team had rectified the error quickly and fix this issue. Today we bring settings steps for you to avoid Error Establishing a Database Connection in WordPress. You can easily re-check these and easily fix this error.
Things that cause Error establishing a database connection in WordPress Localhost
In short, you are getting this error because WordPress is not able to make a connection with database on your localhost. There are several reasons for this problem. Below is the list you have to check step by step to rectify the error and fix it.
1.) Check that setting in wp-config.php is correct. You can see and re-check the settings by reading wp-config.php database settings.
2.) Sometimes database server is unresponsive. You can check this with your hosting provider. If you are sure that database is responsive than you can skip this step.
3.) Can this problem is occur for /wp-admin/ also?. You can simply check this by entering the URL in to your browser. Wp-config.php is front end of WordPress and Wp-admin is back end of WordPress. We want to check that we are getting the same or different error in front & back end.
http://www.example.com/wp-admin/ change the example.com with your website.
If the error is same “error establishing a database connection” on the both pages then proceed to the next step.
If the error is different like “one or more database is unavailable.The database may need to repaired”. In this case you need to repair your database.
You can easily repair the database by adding the following line in you wp-config.php file. This function will add the database repair mode without log in to account.
You can take the back-up of your database by ftp server before repairing. Now you need to go on to the following URL to see the repair settings.
Change yousite.com with your domain name and you can now see the below page.
Please remember to remove the above function you had added in you wp-config.php since any edit your database setting without Log in.
If you are facing problem after database repair & having problem in running the database repair keep on reading this article for more solution.
4.) For those who are having the same error on both wp-config.php & /wp-admin/. You can change the localhost address to IP address in your wp-config.php file. We also change this to IP address and fix this issue.
You local address can be in form of mysql**.localhost.com OR ftp**.example.com OR sql**.example.com.
Most of the time website IP address is same as the database IP address. You can convert the database address to IP address.
5.) Check you Web Host MySQL server. Some users noticed that their MySQL server is not responsive. This can be happen when you are using shared hosting and due to high traffic your MySQL server become non-responsive. Some users also noticed that their server is responsive but users doesn’t have specific permission.
You can easily check the permission. Go to your CPanel >>> the phpMyAdmin >>> and try to create a dummy file.
If you are successful, that means you everything is OK. now gain check your wp-config.php file and figure our the typo error in the file.
If Not, contact your hosting provider for setting the user permissions. This is because sometime users permission reset automatically.
On some sites we read that users upload the fresh copy of WordPress and fix the error establishing a Database connection with WordPress Localhost.