Can ' t connect to local MySQL server through socket

Source: Internet
Author: User
Tags mysql client mysql version

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

This is a problem where the socket cannot be found when MySQL logs on.

The first thing to understand is that the Linux side of MySQL server startup will open a socket,linux on the MySQL client when the MySQL server is not using IP connection, the default will also be through the socket to link MySQL server.

Socket file for 1.mysql server.

If you do not manually configure MY.CNF, then the default socket is generally DATADIR/mysql.sock , and DATADIR if not manually modified, the default is the/var/lib/mysql directory. Depending on the MySQL version, the default path for the socket may be/tmp/mysql.sock.

For example, I modified the socket path to /data/mysql.sock .

2. The socket file used when the client connects.

On Linux, various MySQL class clients (such as Mysql,mysqladmin,mysqldump,mysqlimport, etc.) connect to MySQL server, if the specified hostname is ' localhost ', A socket is used to connect to MySQL server. Therefore, you must specify the correct sockets for these clients.

Method One: Use the "-S" option on the connection command line to specify

mysqladmin -S /data/mysql.sockmysql -S /data/mysql.sockmysqldump -S /data/mysql.sock

Method Two: Specify in the configuration file
For example, in MY.CNF:

[client]socket=/data/mysql.sock

The configuration of the client segment means that any client connecting to MySQL server uses that segment configuration. Therefore, after this configuration, either MySQL, mysqldump, mysqladmin, or other clients will use socket=/data/mysql.sock the connection.

In addition to using [client] the connection parameters for the specified global client, you can specify connection parameters for specific clients. For example, the following 3 clients for MySQL, mysqldump, mysqladmin, respectively, specify the socket connection parameters.

[mysql]socket=/data/mysql.sock[mysqldump]socket=/data/mysql.sock[mysqladmin]socket=/data/mysql.sock

Note: If you use IP, for example, if you are using the mysql -uroot -h‘192.168.100.10‘ TCP/IP protocol to connect to MySQL, the socket will not be used and there will be no socket to find.

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.