ERROR 2002 (HY000): Can't connect to local MySQL server through socket

在安装好了MySQL之后,使用了新的配置文件后。MySQL服务器能够成功启动,但在登陆的时候出现了ERROR 2002 (HY000): Can‘t connect to local MySQL server through socket,即无法通过socket连接到mysql服务器,同一时候提供了socket文件的位置。以下是这个问题的描写叙述与解决的方法。

1、故障现象
[[email protected] mysqldata]# mysql -uroot -p123456
Warning: Using a password on the command line interface can be insecure.
ERROR 2002 (HY000): Can‘t connect to local MySQL server through socket ‘/data/mysqldata/mysql.sock‘ (111)

#故障环境
[[email protected] mysqldata]# more /etc/issue
CentOS release 5.9 (Final)
Kernel \r on an \m

2、故障分析
#查看mysql实例的状态
[[email protected] mysqldata]# netstat -ntlp  | grep 3306
tcp        0      0 :::3306                     :::*                        LISTEN      13001/mysqld

#查看my.cnf关于socket的配置
[[email protected] mysqldata]# more /etc/my.cnf |grep sock
socket = /tmp/mysql.sock

#由上可知my.cnf中定义的为/tmp文件夹下,而错误提示为/data/mysqldata/文件夹下
#也就是说mysqld已经声称了正确的sock文件,但client连接还是从初始文件夹去找sock文件
#以下查看后台日志,有个ERROR。是关于满查询日志的。是因为文件夹不存在而产生的错误,与当前故障无关
[[email protected] mysqldata]# more SZDB.err
             ............
2014-10-11 13:17:21 13001 [Note] InnoDB: 5.6.12 started; log sequence number 1625997
/app/soft/mysql/bin/mysqld: File ‘/log/mysql_logs/slowquery.log‘ not found (Errcode: 2 - No such file or directory)
2014-10-11 13:17:21 13001 [ERROR] Could not use /log/mysql_logs/slowquery.log for logging (error 2). Turning logging off for the who
le duration of the MySQL server process. To turn it on again: fix the cause, shutdown the MySQL server and restart it.
2014-10-11 13:17:21 13001 [Note] Server hostname (bind-address): ‘*‘; port: 3306
2014-10-11 13:17:21 13001 [Note] IPv6 is available.
2014-10-11 13:17:21 13001 [Note]   - ‘::‘ resolves to ‘::‘;
2014-10-11 13:17:21 13001 [Note] Server socket created on IP: ‘::‘.
2014-10-11 13:17:21 13001 [Note] Event Scheduler: Loaded 0 events
2014-10-11 13:17:21 13001 [Note] /app/soft/mysql/bin/mysqld: ready for connections.
Version: ‘5.6.12-log‘  socket: ‘/tmp/mysql.sock‘  port: 3306  Source distribution
#Author :Leshami
#Blog   : http://blog.csdn.net/leshami

3、解决故障
a、通过配置my.cnf mysql选项socket文件位置解决
#先停止mysql服务器
[[email protected] mysqldata]# service mysqld stop
Shutting down MySQL.[  OK  ]

#改动my.cnf,例如以下
[[email protected] mysqldata]# vi /etc/my.cnf
[mysql]
no-auto-rehash
socket = /tmp/mysql.sock  #加入该行

#重新启动mysql服务器
[[email protected] mysqldata]# service mysqld start
Starting MySQL..[  OK  ]

#再次连接正常
[[email protected] mysqldata]# mysql -uroot -p
Enter password:
mysql> show variables like ‘version‘;
+---------------+------------+
| Variable_name | Value      |
+---------------+------------+
| version       | 5.6.12-log |
+---------------+------------+

b、为socket文件建立链接方式
[[email protected] mysqldata]# ln -s /tmp/mysql.sock /data/mysqldata/mysql.sock
ln: creating symbolic link `/data/mysqldata/mysql.sock‘ to `/tmp/mysql.sock‘: File exists
[[email protected] mysqldata]# rm mysql.sock    #上面提示文件存在,所以删除之前的mysql.sock文件
[[email protected] mysqldata]# ln -s /tmp/mysql.sock /data/mysqldata/mysql.sock
[[email protected] mysqldata]# ls -hltr mysql.sock
lrwxrwxrwx 1 root root 15 Oct 11 14:00 mysql.sock -> /tmp/mysql.sock
[[email protected] mysqldata]# mysql -uroot -p
Enter password:
mysql> show variables like ‘socket‘;
+---------------+-----------------+
| Variable_name | Value           |
+---------------+-----------------+
| socket        | /tmp/mysql.sock |
+---------------+-----------------+

ERROR 2002 (HY000): Can't connect to local MySQL server through socket

时间: 2024-10-10 03:24:12

ERROR 2002 (HY000): Can't connect to local MySQL server through socket的相关文章

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

[[email protected] mysql3307]# /opt/mysql3307/bin/mysql -upisp [email protected]123 mysql: [Warning] Using a password on the command line interface can be insecure. ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.so

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 M

ERROR 2002 (HY000): Can’t connect to local MySQL server through socket ‘/var mysql 启动不了

ERROR 2002 (HY000): Can’t connect to local MySQL server through socket ‘/var mysql 启动不了 ps -A | grep -i mysql kill 列出来的进程 service mysql start 我的问题就解决了 ---------------------------------------------- Fedora8启动mysql 报错:ERROR 2002 (HY000): Can’t connect

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

我在源码编译安装mysql后,虽然mysql服务可以正常启动,但是当我直接执行mysql后,出现了错误. 错误提示如下: [[email protected] ~]# mysql ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2) 出现错误原因: 由于mysql 默认的mysql.sock 是在/var/lib/mysql/mysql.sock,但linux系统总

(MYSQL)ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)

ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2) 方案1. 1.#ps -A|grep mysql 显示类似: 1829 ?        00:00:00 mysqld_safe   1876 ?        00:00:31 mysqld 2.#kill -9 1829 3.#kill -9 1876 4.#/etc/init.d/

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

原因:找不到mysql.sock文件 解决方法: 1 找到mysql.sock文件位置 echo "show variables" | mysql | grep "socket"或者echo "status" | mysql | grep "socket" 2 ln -s /var/lib/mysql /mysql .sock /tmp/mysql .sock 将两个文件做一个软连接 ERROR 2002 (HY000): C

安装mysql后ERROR 2002 (HY000): Can’t connect to local MySQL server through socket ‘/var mysql 启动不了

ps -A | grep -i mysql kill 列出来的进程 service mysql start 我的问题就解决了 ---------------------------------------------- Fedora8启动mysql 报错:ERROR 2002 (HY000): Can’t connect to local MySQL server through socket ‘/var/lib/mysql/mysql.sock’ (2) 1.先查看 /etc/rc.d/ini

ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib

今天在linux里安装mysql,运行时遇到这样的错误 ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' 上网查了下: 这种情况大多数是因为你的mysql是使用rpm方式安装的,它会自动寻找 /var/lib/mysql/mysql.sock 这个文件,通过unix socket登录mysql.常见解决办法如下:1.创建/修改文件 /etc/my.c

(转)ERROR 2002 (HY000): Can't connect to local MySQL server through socket '***' (2)

有时候,当我们使用"mysql"."mysqladmin"."mysqldump"等命令管理数据库时,服务器抛出类似如下错误: 1 ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2) 这个错误是由于什么原因导致的呢? 一.错误现场还原: 下面我们通过三种方式来连接,然后观察提示的错误信息: 1.