Error Establishing a Database Connection in WordPress

Error Establishing a Database Connection is one of those curses that could be caused by many reasons. As a WordPress beginner, this is very frustrating.

In this article, we will show you how to fix the error establishing a database connection in WordPress

Why do you get this error?

You are getting this error because WordPress is unable to establish a database connection.  Now the reason why WordPress is unable to establish a database connection can vary. It could be that your database server is not respons. It could be that your database login credentials are wrong or have been changed. Majority of the times this error happens because of some sort of server error however there could be other factors as well. Now take a look how to solve this problem.

Error Establishing a Database Connection in WordPress

Want to know more about this go WordPress Support

Does the problem occur for /wp-admin/ as well?

You should check that you are getting the same error on both the front-end of the site, and the back-end of the site (wp-admin). If the error is same on both pages “Error establishing a database connection”.  If you are getting a different error on the wp-admin, then you need to repair your database.

Error Establishing a Database Connection in WordPress

Add the following line in your wp-config.php file. Add it just before ‘That’s all, stop editing! Happy blogging’ line wp-config.php.

Once you have done that, you can see the settings by visiting this page: http://www.yoursite.com/wp-admin/maint/repair.php

If this repair did not fix the problem, or you are having trouble running the repair then follow next method.

Checking the WP-Config file

It is most important file in your entire WordPress installation.  If you changed your root and database  password, then you will need to change this file as well. Firstly you check that everything in your wp-config.php file is the same.

 

  1. Define (‘DB_NAME’, ‘database-name’);
  2. Define (‘DB_USER’, ‘database-username’);
  3. Define (‘DB_PASSWORD’, ‘database-password’);
  4. Define (‘DB_HOST’, ‘localhost’);

 

Remember your DB_Host value might not always be localhost. It will be different.

If everything in this file is correct (make sure you check for typos), then it is fair to say that there is something wrong on the server end.

Check your Web Host (MySQL Server)

Your site will get really slow and for some users even output the error. So the best thing you should contact with your hosting provider and ask them if your MySQL server is responsive.  If anyone want to check  MySQL server is running by himself, he can do a few things.

Check other sites on the same server to see if they are having the same issue. If they are, then most definitely there is something wrong with your MySQL server. If you don’t then  go to your cPanel and try to access phpMyAdmin and connect the database. Make a new file called testconnection.php and paste the following code in it:

<?php

$link = mysql_connect(‘localhost’, ‘root’, ‘password’);

if (!$link) {

die(‘Could not connect: ‘ . mysql_error());

}

echo ‘Connected successfully’;

mysql_close($link);

?>

Go back to your wp-config file to make sure that everything there is correct (re-scan for typos).

This is a really frustrating error. I hope this blog helped you, if you need more help contact our WordPress Technical Support Helpline

 

 

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s