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

Source: Internet
Author: User





After installing MySQL, after using 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, you cannot connect to the MySQL Server via the socket and provide the location of the socket file. The following is a description and solution to this problem.


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)

Fault environment
[Email protected] mysqldata]# more/etc/issue
CentOS release 5.9 (Final)
Kernel \ r on an \m

2. Fault Analysis
#View the status of the mysql instance
[Email protected] mysqldata]# NETSTAT-NTLP | grep 3306
TCP 0 0::: 3306:::* LISTEN 13001/mysqld


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

From above, my. CNF is defined in the/tmp directory, and the error is in the/data/mysqldata/directory
That is, mysqld has claimed the correct sock file, but the client connection or the initial directory to find the sock file
Is below an internal query log, is due to the directory does not exist and generated errors, not related to 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
#first stop mysql server
[[Email protected] mysqldata]# service mysqld stop
Shutting down MySQL. [OK]


Modify my. CNF, as follows
[Email protected] mysqldata]# VI/ETC/MY.CNF
[MySQL]
No-auto-rehash
Socket =/tmp/mysql.sock #Add this line

# Restart mysql server
[[Email protected] mysqldata]# service mysqld start
Starting MySQL. [OK]

Connect again normally
[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#The above prompt file exists, 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 ' t connect to local MySQL server through socket


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.