ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock'
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock'相关的知识,希望对你有一定的参考价值。
在安装好了mysql之后,使用了新的配置文件后,MySQL服务器可以成功启动,但在登陆的时候出现了ERROR 2002 (HY000): Can‘t connect to local MySQL server through socket,即无法通过socket连接到mysql服务器,同时提供了socket文件的位置。下面是这个问题的描述与解决办法。
一、故障现象
在登录mysql数据库时报错为如下所示:
~]# mysql -uroot -p
Enter password:
ERROR 2002 (HY000): Can‘t connect to local MySQL server through socket ‘/application/mysql5.1.72/tmp/mysql.sock‘ (2)
二、故障分析
#查看mysql实例的状态
~]# netstat -tunp | grep 3306
tcp 0 0 :::3306 :::* LISTEN 13001/mysqld
#查看my.cnf关于socket的配置
~]# more /etc/my.cnf |grep sock
~]# more /etc/my.cnf |grep sock
socket = /application/mysql5.1.72/tmp/mysql.sock
#由上可知my.cnf中定义的为/tmp目录下,而错误提示为/application/mysql5.1.72/tmp/mysql.sock目录下
#也就是说mysqld已经声称了正确的sock文件,但客户端连接还是从初始目录去找sock文件
三、解决方法
先停止mysql服务器
~]# /etc/init.d/mysqld stop
Shutting down MySQL.[ OK ]
#修改my.cnf,如下
~]# vi /etc/my.cnf
[mysql]
no-auto-rehash
socket = /application/mysql5.1.72/tmp/mysql.sock #添加该行
#重启mysql服务器
~]# service mysqld start
Starting MySQL..[ OK ]
#再次连接正常
~]# mysql -uroot -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.1.72 Source distribution
Copyright (c) 2000, 2013, 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>
本文出自 “叫醒你的不是闹钟而是梦想” 博客,请务必保留此出处http://purify.blog.51cto.com/10572011/1792482
以上是关于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' 。安装后出错
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2) on Mac
FreeBSD 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'/var/run/mysqld/mysqld.sock'
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2) when I
尝试了一切仍然得到 ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (