1. 错误产生
2. 错误产生缘故原由解析
3. 修复问题前预备
3.1 端口是否打开
3.2 mysqld服务是否正在运行
3.3 确定“socket”文件正确位置
4. 问题解决方法
连接Mysql ERROR 2002 (HY000): Can’t connect to local MySQL server through socket ‘/var/lib/mysql/mysql.sock’()
1. 错误产生
[root@server13 ~]# mysql -p
Enter password:
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)
2. 错误产生缘故原由解析
根据设置文件“/etc/my.cnf”的路径,未找到相应的socket文件,就会引发此错误
3. 修复问题前预备
由于“socket”文件是由mysql服务运行时创建的,假如提示“ERROR 2002 (HY000): Can’t connect to local MySQL server through socket ‘***’ (2)”,找不到“socket”文件,我们起重要确认的是mysql服务是否正在运行。
3.1 端口是否打开
[root@server13 ~]# netstat -antlp
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp6 0 0 :::3306 :::* LISTEN 23667/mysqld
3.2 mysqld服务是否正在运行
[root@server13 ~]# /etc/init.d/mysqld status
SUCCESS! MySQL running (23667)
3.3 确定“socket”文件正确位置
[root@server13 ~]# find / -name '*.sock'
/usr/local/mysql/data/mysql.sock
4. 问题解决方法
修改“/etc/my.cnf”设置文件,在设置文件中添加“[client]”选项和“[mysql]”选项,并使用这两个选项下的“socket”参数值,与“[mysqld]”选项下的“socket”参数值,指向的socket文件路径完全一致。如下:
[root@server13 ~]# vim /etc/my.cnf
[root@server13 ~]# cat /etc/my.cnf
[mysqld]
datadir=/usr/local/mysql/data
socket=/usr/local/mysql/data/mysql.sock
symbolic-links=0
server-id=3
[client]
default-character-set=utf8
socket=/usr/local/mysql/data/mysql.sock
[mysql]
default-character-set=utf8
socket=/usr/local/mysql/data/mysql.sock
##修改完后,重启mysqld服务,即可解决此问题
[root@server13 ~]# /etc/init.d/mysqld restart
Shutting down MySQL.. SUCCESS!
Starting MySQL. SUCCESS!
[root@server13 ~]# mysql -p
Enter password:
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.31 Source distribution
Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MySQL [(none)]> exit
Bye
原文链接:https://blog.csdn.net/weixin_45777669/article/details/115671283
© 著作权归作者所有,转载或内容互助请接洽作者
喜欢的朋侪记得点赞、收藏、关注哦!!!
免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!更多信息从访问主页:qidao123.com:ToB企服之家,中国第一个企服评测及商务社交产业平台。 |