使用mysql命令连接mysql服务器时,报ERROR 2002 (HY000): Can't connect to local Mysql server through socket '/tmp/mysql.sock'
1、ps -ef|grep mysqld 查看mysqld的进程是否在,发现mysqld进程在;
2、查看/tmp/mysql.sock文件不在;
3、查看/etc/my.cnf 配置文件
[mysqld]
port = 3306
basedir = /usr/local/mysql/mysql-5.7
datadir = /data/mysql
socket = /var/lib/mysql/mysql.sock #服务端生成sock文件路径
可以看到mysql.sock文件在/var/lib/mysql/mysql.sock目录下,已核实文件存在;
1、建立软链接:ln -s /var/lib/mysql/mysql?.sock ? /tmp/mysql?.sock
2、在配置文件my.cnf中添加
[client]
socket=/var/lib/mysql/mysql.sock #客户端读取sock文件路径