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

ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)

时间:2016-06-24 13:03:29      阅读:246      评论:0      收藏:0      [点我收藏+]

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

在安装好了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' (2)

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

原文地址:http://purify.blog.51cto.com/10572011/1792482

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