2024-02-01 ERROR 2002 (HY000): Can‘t connect to local MySQL server th
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. 错误产生
# mysql -p
Enter password:
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)
https://img-blog.csdnimg.cn/img_convert/7685a3c1bf6f3c3a078236e444ca547c.webp?x-oss-process=image/format,png 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 端口是否打开
# 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服务是否正在运行
# /etc/init.d/mysqld status
SUCCESS! MySQL running (23667)
https://img-blog.csdnimg.cn/img_convert/35ecbc77a56132a45da239b82b3426fa.webp?x-oss-process=image/format,png 3.3 确定“socket”文件正确位置
# find / -name '*.sock'
/usr/local/mysql/data/mysql.sock
https://img-blog.csdnimg.cn/img_convert/453c1d6513d4f745d993f1c2e22c75e3.webp?x-oss-process=image/format,png 4. 问题解决方法
修改“/etc/my.cnf”设置文件,在设置文件中添加“”选项和“”选项,并使用这两个选项下的“socket”参数值,与“”选项下的“socket”参数值,指向的socket文件路径完全一致。如下:
# vim /etc/my.cnf
# cat /etc/my.cnf
datadir=/usr/local/mysql/data
socket=/usr/local/mysql/data/mysql.sock
symbolic-links=0
server-id=3
default-character-set=utf8
socket=/usr/local/mysql/data/mysql.sock
default-character-set=utf8
socket=/usr/local/mysql/data/mysql.sock
https://img-blog.csdnimg.cn/img_convert/46d7aa8d49aa85bebac85ea33ec3233f.webp?x-oss-process=image/format,png ##修改完后,重启mysqld服务,即可解决此问题
# /etc/init.d/mysqld restart
Shutting down MySQL.. SUCCESS!
Starting MySQL. SUCCESS!
# 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://img-blog.csdnimg.cn/img_convert/f59a03c50522c202cd19fe11240eb84f.webp?x-oss-process=image/format,png 原文链接:https://blog.csdn.net/weixin_45777669/article/details/115671283
© 著作权归作者所有,转载或内容互助请接洽作者
https://img-blog.csdnimg.cn/direct/67c64049147741939b85489caefbb597.png
喜欢的朋侪记得点赞、收藏、关注哦!!!
免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!更多信息从访问主页:qidao123.com:ToB企服之家,中国第一个企服评测及商务社交产业平台。
页:
[1]