MySQL Error 2002 (HY000): Can ' t connect to the local MySQL server through Socket_mysql

Source: Internet
Author: User

After the MySQL is installed, the MySQL server can start successfully after using the new configuration file, but the error 2002 (HY000) appears when landing: Can ' t connect to the local MySQL server through socket, That is, unable to connect to the MySQL server through the socket, while providing the location of the socket file. Here is a description and solution to the problem.

1, the phenomenon of failure

Copy Code code as follows:

[Root@szdb mysqldata]# mysql-uroot-p123456
Warning:using a password on the command line interface can is insecure.
ERROR 2002 (HY000): Can ' t connect to the local MySQL server through socket '/data/mysqldata/mysql.sock ' (111)
#故障环境
[Root@szdb mysqldata]# More/etc/issue
CentOS release 5.9 (Final)
Kernel \ r \m

2. Fault Analysis

Copy Code code as follows:

#查看mysql实例的状态
[Root@szdb mysqldata]# NETSTAT-NTLP | grep 3306
TCP 0 0::: 3306:::* LISTEN 13001/mysqld
#查看my. CNF about Socket configuration
[Root@szdb mysqldata]# more/etc/my.cnf |grep Sock
Socket =/tmp/mysql.sock
#由上可知my. CNF is defined in the/tmp directory, and the error hint is in the/data/mysqldata/directory
#也就是说mysqld已经声称了正确的sock文件, but the client connection is still looking for sock files from the initial directory
#下面查看后台日志, there is an error, is about the full query log, is due to the directory does not exist errors, and the current failure has nothing to do
[Root@szdb 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 to the WHO
Le duration of the MySQL server process. To turn it 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

3, solve the fault

A, through the configuration my.cnf MySQL option socket file location solution

Copy Code code as follows:

#先停止mysql服务器
[root@szdb mysqldata]# service mysqld Stop
Shutting down MySQL. [OK]
#修改my. CNF, as follows
[Root@szdb mysqldata]# vi/etc/my.cnf
[MySQL]
No-auto-rehash
Socket =/tmp/mysql.sock #添加该行
#重启mysql服务器
[root@szdb mysqldata]# Service mysqld start
Starting MySQL. [OK]
#再次连接正常
[Root@szdb mysqldata]# Mysql-uroot-p
Enter Password:
Mysql> Show variables like ' version ';
+---------------+------------+
| variable_name | Value |
+---------------+------------+
| Version | 5.6.12-log |
+---------------+------------+

b, to create a link to the socket file

Copy Code code as follows:

[Root@szdb mysqldata]# ln-s/tmp/mysql.sock/data/mysqldata/mysql.sock
ln:creating Symbolic link '/data/mysqldata/mysql.sock ' to '/tmp/mysql.sock ': File exists
[Root@szdb mysqldata]# rm mysql.sock #上面提示文件存在, so delete previous mysql.sock files
[Root@szdb mysqldata]# ln-s/tmp/mysql.sock/data/mysqldata/mysql.sock
[Root@szdb mysqldata]# ls-hltr Mysql.sock
lrwxrwxrwx 1 root Oct 14:00 mysql.sock->/tmp/mysql.sock
[Root@szdb mysqldata]# Mysql-uroot-p
Enter Password:
Mysql> Show variables like ' socket ';
+---------------+-----------------+
| variable_name | Value |
+---------------+-----------------+
| Socket | /tmp/mysql.sock |
+---------------+-----------------+

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.