Error Establishing a Database Connection WordPress Localhost [Solved]

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.        change the 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.

[php]define(‘WP_ALLOW_REPAIR’, true);[/php]

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 with your domain name and you can now see the below page.

Error Establishing a Database Connection WordPress Localhost

Error Establishing a Database Connection WordPress Localhost

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** OR ftp** OR sql**

Most of the time website IP address is same as the database IP address. You can convert the database address to IP  address here.

[php]define(‘DB_HOST’, ‘’);[/php]


[php]define(‘DB_HOST’, ‘’);[/php]

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.

Co-Founder of, Having knowledge of SEO, Coding, Ethical Hacking and WordPress. Launched to enhance user experience.

2 Responses to “Error Establishing a Database Connection WordPress Localhost [Solved]”

  1. Arafat

    Apr 27. 2013

    Sometimes when I click on the “Publish” button to post a new article on my WordPress blog, then this error message appears:

    “”Error establishing a database connection… This either means that the username and password information in your wp-config.php file is incorrect or we can’t contact the database server at localhost. This could mean your host’s database server is down…..””

    Despite the error message appears, my post got published and there is no problem with visiting my site. This error does not come after each post publication. Sometimes it occurs. (My hosting reseller provider changed my server some days ago and this problem began after coming to the new server) What is the problem and how to solve it, please tell …… Thanks.

    • webburr

      Apr 29. 2013

      Change your local host address to IP address and hope this will solve your problem.