Why can't I connect to my sql database? I get the error message: “Can't connect to local MySQL server through socket”

时光毁灭记忆、已成空白 提交于 2019-12-12 05:06:26

问题


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?


回答1:


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.




回答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.




回答3:


Check in mysql user privilages if your user's host is correct.




回答4:


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.



来源:https://stackoverflow.com/questions/711473/why-cant-i-connect-to-my-sql-database-i-get-the-error-message-cant-connect

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!