Now, let’s go back to the File Manager. Open that config file again. I’ll go down and now, this time since I know that my database name and user name are correct. I’ll change my password and click Save Changes and then go back and look at my blog again. Refresh. I am getting the same error message, “Error establishing a database connection.” I know my database name is correct. I know my user is correct but I have an error in establishing a connection.
So, how can I troubleshoot this to eliminate the password? Well, I’ll go back to my Control Panel. I’ll scroll down to look at my databases again, under the MySQL Databases and I can see here my database and my user but there is no way that I am aware of that I can actually look now and see what the password is for that user. So, I am not going to be able to verify whether the password is the problem or not. I know that my database is correct. I know my user is correct but if I am unsure of that password, what I can do through the Control Panel here and you may be able to do the same thing in your Control Panel even if you don’t have cPanel, is I can go down and create a new user and add the new user to the database.
So, I’ll come here under Add New User and just pick another one. So, we’ll call this figaro1. I’ll generate a password. So, that is a good, strong password. Copy the password that is going to be assigned to the user figaro1 and create that user. The user is created. I’ll go back and then go down and add the user figaro1 to the database I am using for my WordPress blog. So, I’ll click Add. Give that user All Privileges, Make Changes, go back. Now, I can see that my figaro1 user has also been added to the blog. Now, I could remove figaro if I wanted and it’s probably a good idea to do that unless, you have a reason for having more than one user on a database. So, I’ll just click the X here to remove my old user from the database. Click Yes.
So now, I’ve just added a new user to my database. So, I know the user name and I know the password both. So then, I can go back to my File Manager, Edit the config file, change my user, my DB user to figaro1 and then go down and put in the password that I know is correct for figaro1 and then Save Changes.
So now, if I go back, if I did everything correctly and the password was causing the problem, when I go to my blog and refresh, then it should come back up. So, if those techniques I’ve troubleshot the database name, the user and the password, if you do all those things and you still can not connect to database, then the last thing to do is to check that DB connect.
So, let’s go back again to wp-config and I’ll click Edit. Now, as it says in your config file when you’re initially setting up most of the time, localhost will be your host name, your DB connect but it’s getting to a point where a lot of hosts are not allowing that. Some that I know or one that I know that don’t allow it for example is Go Daddy. If you’re hosting on Go Daddy, you’re not going to be able to use localhost. You will have something different to put in there. So, let me just make a localhost something else and show you what happens. Click Save Changes. So now, I have the incorrect DB host in my config file. Go back to my blog and I get the same error message.
So, you can see here, anyone of those four items will cause this error in establishing a database connection. You have to make sure that all four are correct. So, go back to my wp-config file, Edit and I am going to fix this by saying localhost.
Now again, if you’re on a server, if you’re with a provider that doesn’t allow localhost, then you need to find out from your provider somewhere what you do need to put in here. Sometimes that information will be made available to you in your Control Panel where you create or edit your databases. Sometimes you may have to get that information from your host and provider. Instead of localhost, it could be that you need to put an IP address in here or it could be that you have a longer address in here like database1.hostname.something else. So, it could be virtually anything that goes into your DB host here, your connect information. So, if you’re certain that these three things are correct, then chances are, your problem is going to be in this DB host. One of these four things is going to be causing the problem if you have a problem of connecting, change it back to locahost, hit Save Changes and then, when I go back and refresh; now I can see my blog again.
Now, while I am here, let me show you a couple of other things that you could run into with problems. Let’s go back to our File Manager and look at wp-config file and click Edit. Now, one of the things that you could run into a problem when you’re moving databases and things such as that or moving host or whatever is that down, you’re going to have a Table Prefix for your database. Now, if the Table Prefix is incorrect and your wp-config file, you’re going to get a different error than you would get if any of these other four were incorrect. If any of these are incorrect, we know you’re going to get that error, “can not connect to database.”
If the Prefix is incorrect, let me just change this to xq, anything. It doesn’t really matter and hit Save Changes. Then if you go back to your blog and look at it and hit Refresh, now it’s going to recognized that the database is there but is not going to recognize that your blog is set up and it’s going to prompt you to set up your blog again. If you go through the screens and fill this out, then what you’re really doing is setting up a brand new fresh empty blog because it will create a second set of tables in your database with that prefix that’s in your config file. So, that’s a different error here than the other ones because it can find the database, it just can’t find the tables in that database that belongs to your blog.
So, hopefully this short tutorial sort of overview gives you an idea what to look for and how to do some basic troubleshooting if you get that error, “can not connect to database” to see whether it’s your database name, your user name, your user password or the database connect information. I can almost guarantee you if you get that error, it’s going to be one of those four items in your wp-config file that is incorrect. So, that’s where you need to start to troubleshoot and narrow down the problem.
Never show your wp-config.php file information to anyone like I have here. Doing so will compromise the security of your site.
Transcription by:
Scribe4you Transcription Services