码迷,mamicode.com
首页 > 数据库 > 详细

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

时间:2016-10-12 23:41:56      阅读:188      评论:0      收藏:0      [点我收藏+]

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

安装完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

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

原文地址:http://pengjc.blog.51cto.com/9255463/1861088

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!