mysql cannot find or connect to the local mysql.sock problem

Similar to the following error
Can't connect to local MySQL server through socket '/var/mysql/mysql.sock'

or other paths, such as /var/lib/mysql/mysql.sock


There are many solutions online, that is to configure my .cnf or my.ini, for different operating systems and versions,
we clearly configured the path in my.cnf, but it still doesn’t work


First, understand the role of mysql.sock, which is responsible for some information files recorded when mysql establishes a socket connection
For example, we have changed the data file directory of mysql, and after modifying the configuration file, it cannot be started or connected. We know the function of the mysql.sock file


above , and then analyze several possibilities instead of directly trying to solve the problem
. Whether the file path location of the current user has the corresponding read and write permissions for the current user, otherwise even if MySQL reads the configuration file, it cannot perform the write operation or create the file, and an error will be reported.
You can try the following, authorize
chown -R mysql in the corresponding directory .Second


, restart after the configuration is completed to see if the startup can be successful, and check whether the corresponding file is generated in the corresponding directory. If it is generated, it means that the file permissions are in effect. If it is not generated, it is necessary to judge the current configuration file read by MySQL Whether it is my.cnf, of course, it will be this file by default, unless parameters are added when starting, of course, make sure not to restart the mysqld service to see if the port has been started.


Third, if the MySQL service is successfully started, it means that the server has started normally, but this problem may still occur when connecting to the client, then the prompt for connecting to the client is still the default path, not the my.cnf file. The configured path, at this time, you can connect to mysql by appending the parameter -S file path after the client connecting to mysql, but this is not convenient, we can append
[client]
socket=/var/lib/mysql to my.cnf /mysql.sock or a custom directory, so that when connecting to a local client, it will read and write files like this file directory.

There is also a soft connection on the Internet through ln -s resume to connect the default directory read by mysql to a custom directory, but I always feel that this is a temporary solution and it is very awkward, although it can solve the problem

. more details, please refer to the official website Documentation
http://dev.mysql.com/doc/refman/5.7/en/option-files.html

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326841667&siteId=291194637