ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2) 报错解决方案
2017-12-14 00:00
706 查看
背景
# [root@localhost ~]# uname -a Linux localhost.localdomain 3.10.0-514.el7.x86_64 #1 SMP Tue Nov 22 16:42:41 UTC 2016 x86_64 x86_64 x86_64 GNU/Linux # [root@localhost ~]# mysql --help | grep Distrib mysql Ver 14.14 Distrib 5.6.35, for linux-glibc2.5 (x86_64) using EditLine wrapper
MySQL是用二进制免编译包安装的,修改my.cnf配置文件后,登录MySQL出错。
[root@localhost ~]# mysql -uroot -p123456 Warning: Using a password on the command line interface can be insecure. ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)
报错解释
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)意思是说MySQL Server服务和socket正确连接,错误代码 2002 (HY000)
解决方案
MySQL配置文件中加上如下[client],再登录mysql。[root@localhost ~]# vim /etc/my.cnf ....... [mysqld] datadir=/data/mysql socket=/tmp/mysql.sock server-id=181 ....... #添加上client [client] socket=/tmp/mysql.sock [root@localhost ~]# /etc/init.d/mysqld restart #重启 Shutting down MySQL.. SUCCESS! Starting MySQL. SUCCESS!
问题就解决了。
关于MySQL的server、client、sock的关系
server - 简单的解释就是服务端client - 简单的解释就是客户端
sock - 简单的解释就是专门用来连接上面两者的socket文件
因为,同一台物理服务器中,MySQL的server和client是在一起的,mysql.sock作为两者的连接文件存在的。如果是在不同的两台物理服务器中,那么一般是使用TCP/IP套接字文件连接的。
相关文章推荐
- ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)
- Mysql连接错误:ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (
- ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)
- 阿里云报错:ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock’
- CentOS下面ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)
- 解决“ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (60)”
- 解决“ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (111)”
- 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 '/tmp/mysql.sock' (2)
- ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)
- mysql连接之ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2
- 解决ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)
- 记一次 ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock’(2) 排错流程
- ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)
- CentOS下面ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)
- mac ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)
- ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)
- ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)
- ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock'
- ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock'