ERROR 2002 (HY000): can& #39; t connect to local MySQL server through socket

Source: Internet
Author: User
Tags tmp folder

After you have installed MySQL, use the new configuration file. The MySQL server can start successfully, but at the time of login error 2002 (HY000): Can ' t connect to local MySQL server through socket, that is, unable to connect through the socket to MySQL servers, The location of the socket file is provided at the same time. The following is a description of the problem and the solution of the method.

1, fault phenomenon
[Email protected] mysqldata]# mysql-uroot-p123456
Warning:using a password on the command line interface can is 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. Fault Analysis
#查看mysql实例的状态
[Email protected] mysqldata]# NETSTAT-NTLP | grep 3306
TCP 0 0::: 3306:::* LISTEN 13001/mysqld

#查看my. CNF configuration for sockets
[Email protected] mysqldata]# more/etc/my.cnf |grep sock
Socket =/tmp/mysql.sock

#由上可知my. CNF is defined in the/tmp folder, and the error message is under the/data/mysqldata/folder
#也就是说mysqld已经声称了正确的sock文件, but the client connection is still from the initial folder to find the sock file
#以下查看后台日志, there is an error. is about the full query log. Error due to the absence of a folder, regardless of the current failure
[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
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, solve the problem
A, by configuring the MY.CNF MySQL option socket file location resolution
#先停止mysql服务器
[[Email protected] mysqldata]# service mysqld stop
Shutting down MySQL. [OK]

#改动my. CNF, for example the following
[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. Establish a link for the socket file
[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#上面提示文件存在, so delete the previous Mysql.sock file
[Email protected] mysqldata]# ln-s/tmp/mysql.sock/data/mysqldata/mysql.sock
[Email protected] mysqldata]# ls-hltr Mysql.sock
lrwxrwxrwx 1 root root the Oct Mysql.sock-/tmp/mysql.sock
[Email protected] mysqldata]# mysql-uroot-p
Enter Password:
Mysql> Show variables like ' socket ';
+---------------+-----------------+
| variable_name | Value |
+---------------+-----------------+
| sockets | /tmp/mysql.sock |
+---------------+-----------------+

ERROR 2002 (HY000): can& #39; t connect to local MySQL server through socket

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.