ERROR 2002 (HY000) /tmp/mysql.sock

2016年8月4日 0 条评论 577 次阅读 0 人点赞

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

本地登陆mysql提示

[[email protected] default]# mysql -i 127.0.0.1
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)

解决方法:

由于mysql 默认的mysql.sock 是在/var/lib/mysql/mysql.sock,但linux系统总是去/tmp/mysql.sock查找,所以会报错,所以查找到正确的位置:

[[email protected] default]# find / -name "mysql.sock"
/tmp/systemd-private-9b22543919a542fe83203e70d30920d2-vpn.service-vhaYd1/tmp/mysql.sock

方法一:直接指定mysql通道

[[email protected] default]# mysql --socket=/tmp/systemd-private-9b22543919a542fe83203e70d30920d2-vpn.service-vhaYd1/tmp/mysql.sock
Welcome to the MySQL monitor.  Commands end with ; or /g.
Your MySQL connection id is 2 to server version: 5.0.22
Type 'help;' or '/h' for help. Type '/c' to clear the buffer.
mysql>

方法二:创建符号连接:

#为mysql.sock增加软连接(相当于windows中的快捷方式)。
ln -s /tmp/systemd-private-9b22543919a542fe83203e70d30920d2-vpn.service-vhaYd1/tmp/mysql.sock /tmp/mysql.sock
[[email protected] default]# ln -s /tmp/systemd-private-9b22543919a542fe83203e70d30920d2-vpn.service-vhaYd1/tmp/mysql.sock /tmp/mysql.sock
[[email protected] default]# mysql -u root -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or /g.
Your MySQL connection id is 2 to server version: 5.0.22
Type 'help;' or '/h' for help. Type '/c' to clear the buffer.
mysql>

Sevenfal

这个人太懒什么东西都没留下

文章评论(0)