centos7 mysql异常ERROR 2002 (HY000)分析解决
程序员文章站
2022-04-14 13:44:44
...
1.错误信息:
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock'
2.出现问题原因:
有可能是 my.cnf 配置文件中设置了 [mysqld] 的参数 socket ,而没有设置[client]的参数socket
3.mysql.sock 文件有什么用:
mysql 支持 socket 和 TCP/IP 连接。那么 mysql.sock 这个文件有什么用呢?连接localhost通常通过一个Unix域套接字文件进行,一般是/tmp/mysql.sock。如果套接字文件被删除了,本地客户就不能连接。/tmp 文件夹属于临时文件,随时可能被删除。
3.1 TCP 连接
(如果报错 /tmp/mysql.sock,你可以尝试这种方式连接)
mysql -uroot -h 127.0.0.1 -p
3.2.socket 连接
mysql -uroot -p
4.解决方式
添加 [client] 配置项,如下所示
4.1配置前:
(配置 [client] 前,会报错’/tmp/mysql.sock’ (2))
[mysqld]
datadir=/usr/local/mysql/data
basedir=/usr/local/mysql
socket=/var/lib/mysql/mysql.sock
user=mysql
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
[mysqld_safe]
log-error=/usr/local/mysql/mysqld.log
pid-file=/usr/local/mysql/mysqld.pid
4.2配置后
(配置 [client] 后,重启 mysql服务)
[mysqld]
datadir=/usr/local/mysql/data
basedir=/usr/local/mysql
socket=/var/lib/mysql/mysql.sock(跟这个socket路径一样)
user=mysql
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
[mysqld_safe]
log-error=/usr/local/mysql/mysqld.log
pid-file=/usr/local/mysql/mysqld.pid
[client]
port=3306
socket=/usr/local/mysql/mysql.sock
参考链接:https://www.jb51.net/article/174244.htm
下一篇: There was an unexpected error (type=Method Not Allowed, status=405). Request method ‘POST‘ not suppo
推荐阅读
-
Mysql启动报ERROR:2002的分析与解决
-
mysql中异常错误ERROR:2002的解决方法
-
MySQL错误 ERROR 2002 (HY000): Can't connect to local MySQL server through socket 的解决办法
-
Mysql启动报ERROR:2002的分析与解决
-
ERROR 2002 (HY000): Can‘t connect to local MySQL server through socket ‘/tmp/mysql.sock‘ (2)已解决
-
Mysql中ERROR 2002 (HY000)错误的解决_MySQL
-
解决mysql登陆时出现“ERROR 2002 (HY000): Can't conne_MySQL
-
Mysql中ERROR 2002 (HY000)错误的解决_MySQL
-
解决mysql登陆时出现“ERROR 2002 (HY000): Can't connect..”_MySQL
-
mysql中异常错误ERROR:2002的解决方法分享