安装完mysql连接报错:
[root@localhost app]# mysql ERROR 2002 (HY000): Can‘t connect to local MySQL server through socket ‘/var/lib/mysql/mysql.sock‘ (2) [root@localhost app]# mysql -uroot -p Enter password: ERROR 2002 (HY000): Can‘t connect to local MySQL server through socket ‘/var/lib/mysql/mysql.sock‘ (2)
分析:error
Can‘t connect to local MySQL server through socket ‘/var/lib/mysql/mysql.sock‘
查询自己的 mysql.sock文件
发现自己的路径在
[root@localhost data]# find / -name mysql.sock /tmp/mysql.sock
则在 my.cnf 中添加指定 mysql.sock文件
[root@localhost data]# vim /etc/my.cnf [mysqld] socket=/tmp/mysql.sock
fack!! 重启mysql服务问题依旧存在
于是添加软连接
[root@localhost data]# mkdir -pv /var/lib/mysql mkdir: 已创建目录 “/var/lib/mysql” [root@localhost data]# ln -s /tmp/mysql.sock /var/lib/mysql/mysql.sock [root@localhost data]# mysql Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 1 Server version: 5.6.16 Source distribution Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners. Type ‘help;‘ or ‘\h‘ for help. Type ‘\c‘ to clear the current input statement. 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
原文:http://pengjc.blog.51cto.com/9255463/1861088