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

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了mysql连接报错 ERROR 2002 (HY000): Can't connect to local MySQL server through socket相关的知识,希望对你有一定的参考价值。

安装完mysql连接报错:

[[email protected] app]# mysql
ERROR 2002 (HY000): Can‘t connect to local MySQL server through socket ‘/var/lib/mysql/mysql.sock‘ (2)
[[email protected] 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文件

发现自己的路径在 

[[email protected] data]# find / -name mysql.sock
/tmp/mysql.sock

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

[[email protected] data]# vim /etc/my.cnf
[mysqld]
socket=/tmp/mysql.sock


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

于是添加软连接

[[email protected] data]# mkdir -pv /var/lib/mysql
mkdir: 已创建目录 “/var/lib/mysql”
[[email protected] data]# ln -s /tmp/mysql.sock /var/lib/mysql/mysql.sock
[[email protected] 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的主要内容,如果未能解决你的问题,请参考以下文章

thinkphp 数据库连接报错 SQLSTATE[HY000] [2002] No such file or directory

MYSQL数据库连接报错解决办法

MySql证书问题使用SSL连接报错

mac mysql连接报错ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using pa

Mysql远程连接报错:SQL Error (1130): Host '192.168.6.128' is not allowed to connect to this MySQL s

请教ubuntu10.04 mysql连接报错 ERROR 2003 (HY000): Can't connect to MySQL server on 请问是啥原因?