在Linux服务器上安装好mysql后登录时出现以下问题
ERROR 2002 (HY000): Can‘t connect to local MySQL server through socket ‘/var/lib/mysql/mysql.sock‘
查找mysql.sock 文件,命令如下:
find -name mysql.sock
结果如下:
文件存在,但是不存在/var/lib/mysql目录下,做一个软连接即可,在这之前先确定当前用户为root用户,命令为 whoami
由普通用户切换到root用户,su 回车,输入密码即可进入root
关闭mysql数据库,命令如下:
/usr/local/mysql/support-files/mysql.server stop
将/tmp/mysql.sock 设置软连接到 /var/lib/mysql/mysql.sock
命令如下:
ln -s /tmp/mysql.sock /var/lib/mysql/mysql.sock
重新启动mysql
/usr/local/mysql/support-files/mysql.server start
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock'