Focus on cloud service provider activities
Notes on website operation and maintenance

Solution to mysql.sock's failure to find this file

When we ran the O&M server, we saw that MySQL could not be connected and when we restarted the database, we were prompted that the mysql.sock file could not be found. How can we solve this problem? For example, when restarting the database, we saw the problem of "Can't connect to local MySQL server through socket '/tmp/mysql. socket'". How to solve the problem that the file cannot be found? We check that the path of the sock file is set incorrectly, the permissions of the directory where the sock file is located, and the mysql.sock file is missing.

How to solve it?

1. Check whether the service is started.

2. Check the path specified by the socket parameter in the my.cnf file to see if the path has access permissions.

3. Go down to that path to see if there is a mysql.sock file. If there is no sock file in this path, we first use the find command to find the location of this file. If find cannot find it, restart the mysql service and a file will be automatically generated. Then copy it to the path specified by the sortek parameter. Here we establish a soft connection, which is also a recommended method. For example, this file is in/var/lib/mysql.sock, and the path specified by the socket parameter is/tmp/mysql.sock.

We can create:

 ln -s /var/lib/mysql.sock /tmp/mysql.sock

After creation, try to connect to the database again to see if it is normal.

We need to note that the mysql.sock file is in/tmp by default. When the database starts, the system also defaults to this file to find the mysql.sock file, but the/tmp directory is sometimes cleared by a scheduled task. Then we can add a sticky permission to the/tmp directory to protect it from deletion. chmod+t/tmp is enough, The file under/tmp can only be deleted by the file owner and root user.

4. If the error is still reported, we can use TCP/IP to connect.

 mysql -uroot -h 127.0.0.1 -p
Like( zero )
Do not reprint without permission: Lao Zuo's Notes » Solution to mysql.sock's failure to find this file


Scan the code to follow the official account

Get more news about webmaster circle!
Entrepreneurship, operation and new knowledge