In mysql, the 2022 error refers to the fact that the socket is not specified during compilation, so the default value is still used when the mysql command is connected. Because the socket location has changed and the mysql command does not know it, it appears. For such errors, you can modify the "/etc/my.cnf" file to resolve the error.
The operating environment of this tutorial: windows10 system, mysql8.0.22 version, Dell G3 computer.
First reproduce the problem phenomenon, the error message is as follows:
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)##Error analysis, the official website roughly means It means that the socket was not specified during compilation, so the mysql command still used the default value (/tmp/mysql.sock) when connecting. Because the socket location has changed and the mysql command does not know it, such an error occurred The solution is to tell the mysql command where our socket file is. Modify the /etc/my.cnf file and add the following content:
[mysqld] socket=/data/mysql5.7.24/db_test/mysql.sock [client] socket=/data/mysql5.7.24/db_test/mysql.sockAfter saving, test whether you can log in normally
mysql -uroot -pAnother solution is to specify the socket when logging in. The first way of writing
mysql -uroot -p --socket=/data/mysql5.7.24/db_test/mysql.sockThe second way of writing
mysql -uroot -p -S /data/mysql5.7.24/db_test/mysql.sockRecommended learning:
The above is the detailed content of What is the 2002 error of mysql?. For more information, please follow other related articles on the PHP Chinese website!