当前位置:Gxlcms > 数据库问题 > mysql连接报错 ERROR 2002 (HY000): Can't connect to local MySQL server through socket

mysql连接报错 ERROR 2002 (HY000): Can't connect to local MySQL server through socket

时间:2021-07-01 10:21:17 帮助过:14人阅读


查询自己的 mysql.sock文件

发现自己的路径在 

  1. [root@localhost data]# find / -name mysql.sock
  2. /tmp/mysql.sock

则在 my.cnf 中添加指定 mysql.sock文件

  1. [root@localhost data]# vim /etc/my.cnf
  2. [mysqld]
  3. socket=/tmp/mysql.sock


fack!! 重启mysql服务问题依旧存在

于是添加软连接

  1. [root@localhost data]# mkdir -pv /var/lib/mysql
  2. mkdir: 已创建目录 “/var/lib/mysql”
  3. [root@localhost data]# ln -s /tmp/mysql.sock /var/lib/mysql/mysql.sock
  4. [root@localhost data]# mysql
  5. Welcome to the MySQL monitor.  Commands end with ; or \g.
  6. Your MySQL connection id is 1
  7. Server version: 5.6.16 Source distribution
  8. Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved.
  9. Oracle is a registered trademark of Oracle Corporation and/or its
  10. affiliates. Other names may be trademarks of their respective
  11. owners.
  12. Type ‘help;‘ or ‘\h‘ for help. Type ‘\c‘ to clear the current input statement.
  13. mysql>


问题解决!!!


疑问:在安装 mysql的时候已经通过-DMYSQL_UNIX_ADDR=/tmp/mysql.sock 指定了,但为什么没有生效?




本文出自 “愿与您分享” 博客,请务必保留此出处http://pengjc.blog.51cto.com/9255463/1861088

mysql连接报错 ERROR 2002 (HY000): Can't connect to local MySQL server through socket

标签:error 2002 (hy000): can't connect to local mysql server through socket '/var/lib/mysql/mysql.sock'

人气教程排行