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

在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

结果如下:

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

 

 文件存在,但是不存在/var/lib/mysql目录下,做一个软连接即可,在这之前先确定当前用户为root用户,命令为 whoami

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

由普通用户切换到root用户,su 回车,输入密码即可进入root

关闭mysql数据库,命令如下:

/usr/local/mysql/support-files/mysql.server stop

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

 

 

将/tmp/mysql.sock 设置软连接到 /var/lib/mysql/mysql.sock

命令如下:

ln -s /tmp/mysql.sock /var/lib/mysql/mysql.sock

ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/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'

 

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

上一篇:解决代码在涉及多线程操作数据库时报错:pymysql.err.InternalError: Packet sequence number wrong - got 101 expected 2


下一篇:mysql长连接和短连接的问题