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