Skip to content Skip to sidebar Skip to footer

How to Solve the Error Establishing a Database Connection in WordPress.

How to Solve the Error Establishing a Database Connection in WordPress.
If you have been surfing the web for a while, you have at least seen this error a few times. Error Establishing a Database Connection is one of those curses that could be caused by many reasons.
As a WordPress beginner, this could be awfully frustrating specially when it happened on its own without you replacing anything. We ran into this issue yesterday on our own site. It took a little over 20 subroutine to detect and guidelines the problem. While performance the research to discovery possible causes, we realized that there was no good article that covered everything. In this article, we evidence market you how to location the error founding a database context in WordPress by compiling a list of answer all in one place.

Why do you get this error?

Well in short, you are becoming this error because WordPress is unable to establish a database connection. Now the sight why WordPress is unable to establish a database background can vary. It could be that your database login credentials are wrong or have been changed. It could be that your database waiter is unresponsive. It could be that your database has been corrupted. In our experience, majority of the times this error happens because of some temperament of server erroneousness however there could be other agent as well. Lets profits a look at how to go roughly troubleshooting this problem.

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

First entity you should do is to type sure that you are getting the same incorrectness on both the front-end of the site, and the back-end of the ownership (wp-admin). If the inaccuracies poster is the same on both pages “Error groundwork a database connection”, then proceed onto the next step. If you are getting a different error on the wp-admin for instance something like “One or more database tables are unavailable. The database may task to be repaired”, then you belongings to repair your database.

You can do this by adding the chasing line in your wp-config.php file. Add it just before ‘That’s all, stop editing! Happy blogging’ queue wp-config.php. 

[define('DB_HOST', '127.0.0.1:8889');]

IP’s will vary for online web hosting services.

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)

Often you evidence notice this Error founding database connection when your grounds gets swarmed with a yards of traffic. Basically, your multitude server just cannot handle the burden (specially when you are on shared hosting). Your site testament get really slow and for some users even output the error. So the best thing you should do is get on the phone or livechat with your hosting provider and ask them if your MySQL waiter is responsive.

For those exploiter who poverty to try if MySQL server is running yourself, you can do a few things. Test other sites on the same server to see if they are owning the issue. If they are also becoming the same error, then most definitely there is something harm with your MySQL server. If you do not have any other grounds on this same hosting account simply go to your cPanel and trial to entrees phpMyAdmin and connect the database. If you can connect, then we poverty to verify if your database exploiter has sufficient permission. Create a new queue called testconnection.php and paste the chasing code in it: 

[<?php
$link = mysql_connect('localhost', 'root', 'password');
if (!$link) {
die('Could not connect: ' . mysql_error());
}
echo 'Connected successfully';
mysql_close($link);
?>]

Make sure to replace the username and password. If the connected successfully, then it food that your user has sufficient permission, and there is something else that is wrong. Go back to your wp-config line to make sure that everything there is correct (re-scan for typos).

If you cannot connect to the database by going to phpMyAdmin, then you know it is something with your server. It does not necessarily food that your MySQL server is down. It could mean that your user does not have sufficient permission.

In our case, our MySQL server was running. All other sites on the servers were handling fine except for WPBeginner. When we tried departing to our phpMyAdmin, we ended up getting the error:

#1045 – Access denied for exploiter ‘foo’@’%’ (using password: YES)

We got on the phone with HostGator and their sustenance quickly found the problem. Somehow our user’s dispensation were reset. Not sure how that happened, but apparently that was the reason. They went back in and restore the dispensation and we were able to get the premises back live.

So if you get the entrees denied error in either joining to your phpMyAdmin or through testconnection.php results, then you should conspiracy your multitude prerogative away to get them to location it.

Solutions that Worked for Others

It is important to note, that these may not vocation for you. Use at your own risk and make sure that you have sufficient spare if anything goes wrong.

[UPDATE wp_options SET option_value='YOUR_SITE_URL' WHERE option_name='siteurl']

Make sure to replace YOUR_SITE_URL with the actual url example: http://www.your-url-site.com. The wp_options will be different if you have changed the default WordPress database prefix.

This seemed to fix the issue for him and few others that commented on his post as well.

Sachinum suggested that he was able to connect the database with testconnection.php, so he changed the wp-config.php user to the root user. WordPress started to work perfectly fine. Then he reverted the settings back to the database-user, and it continued to work. He could not figure out what was wrong, but concluded that it was a typo.

Post a Comment for "How to Solve the Error Establishing a Database Connection in WordPress."