Why can't I connect to my sql database? I get the error message: “Can't connect to local MySQL server through socket”
Question
I just moved my site to a new web host, and after changing the database-login file, it still can't connect. I get the following error:
Warning: mysql_query() [function.mysql-query]: Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2) in /usr/www/users/simpleof/index.php on line 91
I changed the password and tried again, but it still doesn't work. All the information in the db-login is correct, so why can't I connect to the database?
Solution 2
Wow. I feel pretty dumb, but I put an extra space into the server name when I logged in.
So my advice to anyone else having this problem is REALLY check to make sure your log-in info is correct.
OTHER TIPS
Is the MySQL server on the same host as the web application? If not, you can't use a socket connection, and will need to connect via TCP.
If the MySQL server is on the same host, then maybe the socket is in a different location than '/tmp/mysql.sock'?
Without more information about what application/platform you're using, that's about all the help I can give.
Check in mysql user privilages if your user's host is correct.
There was a recent update to Debian/Ubuntu which caused this error for me. I had to tweak some of the Ubuntu config to mysql work. You may want to check with your hosting company and see if this is the problem.