Error reason: The socket file does not exist in the/var/lib/mysql directory.
There are two ways to connect to a MySQL server: A TCP connection, a socket file connection. Through the socket file, start the MySQL service, the MySQL service will automatically generate a sock file, the resulting sock file is placed by default--datadir=/var/lib/mysql,mysql default from/var/lib/ The MySQL directory reads the sock file.
Workaround:
1, see if/var/lib/mysql/mysql have Mysql.sock file
2, no mysql.sock, restart the MySQL service, see if there is.
3, no words, PS aux|grep mysql|grep-v ' grep ' to see the MySQL service generated sock in which directory to see if this directory is there.
4. If the MySQL service is generated in another directory, the solution is:
method One, modify the directory generated by the MySQL service, in my.cnf [mysqld] Socket
method Two, MySQL reads the sock file from the/var/lib/mysql/, establishes a soft connection, or copy comes over
method Three, modify the MySQL read directory, in MY.CNF [MySQL] socket
method Four, start the specified socket,mysql-uroot-p123456--socket= '/var/lib/mysql/mysql.sock '
Note:
1, through the socket, can only be connected on the local machine.
2, the use of-hlocalhost is through the socket, not through the network, through the netstat to see the TCP connection, you can think of MySQL and Mysql.sock file interaction, write data inside, read data from the inside.
3, the use of-h127.0.0.1 is through TCP, through the Netstat can see the connection.
MySQL Can ' t connect to local MySQL server through socket '/var/lib/mysql/mysql.sock ' (2)