[Reprint] respond /tmp/mysqld.sock loss problems

Loss problem to deal with /tmp/mysqld.sock

https://blog.csdn.net/endzhi/article/details/86697460

 


Mysql has two connections:
(1) TCP / IP
(2) socket
mysql.sock is to create a socket communication endpoint associated with the mysqld MySQL server to be used, is included with every generation mysql server startup, the default permissions srwxrwxrwx

Socket link means such as the following two ways
mysql -uroot -p123456 (undefined host)
MySQL -uroot--H localhost -p

mysql -uroot -p123456
ERROR 2002 (HY000): Can’t connect to local MySQL server through socket ‘/tmp/mysqld.sock’

Mysql.sock your file does not exist, you may be deleted. Common is emptied manually or cron / tmp / directory.
Connections to localhost usually by a Unix domain socket file, usually /tmp/mysql.sock. If the socket file is deleted, local client can not connect.

Temporary solution
method
to query the true position by find / -name mysql.sock,
that the use of mysql -uroot -p123456 -S /mysql/mysqld.sock socket files can be forced landing.

Method 2
uses TCP link mode

mysql -u user1 -h 127.0.0.1 -p123456

Permanent solution
directly restart mysql mysqld.sock to generate a new file, and update the information, to solve the problem of lost.
The mysqld.sock put mysql installation directory and reduce the risk / tmp is emptied brings.
Modified in my.cnf
socket = /opt/mysql/mysqld.sock
restart mysql service, to a new location to generate a new mysqld.sock

Note: Modifying non /tmp/mysqld.sock encounter other problems, and PHP is the standard configuration to connect to the database through the '/tmp/mysql.sock',
solution "to create a soft link"

ln -s /opt/mysql/mysqld.sock /tmp/mysqld.sock

if it is reported that this loss may be due to MySQL did not even start running, (mysqld.sock disappear with the closure of MySQL).
----------------
Disclaimer: This article is the original article CSDN bloggers "endzhi", and follow CC 4.0 BY-SA copyright agreement, reproduced, please attach the original source link and this statement. .
Original link: https: //blog.csdn.net/endzhi/article/details/86697460

Guess you like

Origin www.cnblogs.com/jinanxiaolaohu/p/12387258.html