mysql连接之ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2

连接mysql数据库时出现如下错误:ERROR 2002 (HY000): Can’t connect to local MySQL server through socket ‘/tmp/mysql.sock’ (2)

可能的解决办法
1)确定自己安装的mysql是mysql-server而不是mysql-client。
2)查看mysql-server是否启动(我的问题就是因为没有启动),若没启动则启动mysql-server(启动方式很多详见:http://blog.sina.com.cn/s/blog_4b0e31860100hbjk.html mysql5.6的启动命令方式是:到/usr/local/mysql/support-files目录下执行:mysql.server start)。
3)查看mysql配置文件:
/etc/my.cnf
/etc/mysql/my.cnf
在/etc/my.cnf中和在/etc/mysql/my.cnf中配置的socket文件位置的参数有可能不一致,删除掉/etc/mysql/my.cnf,让mysql以 /etc/my.cnf为准, 即可解决问题。

参考:https://stackoverflow.com/questions/15450091/for-a-newbie-error-2002-hy000-cant-connect-to-local-mysql-server-through-so

https://stackoverflow.com/questions/11657829/error-2002-hy000-cant-connect-to-local-mysql-server-through-socket-var-run

你可能感兴趣的:(mysql)