Failed to connect to MySQL: Can't connect to local MySQL server through socket'/tmp/mysql.sock' (111)

When investigating problems, be sure to pay attention to the error code indicated in the error message. The information in this article is 111
In addition, the places to be considered are: code, system environment, software configuration, etc. It is necessary to analyze in combination with the scene.

1. Problem performance

  • In using the command line local connections MySQL can succeed
  • Use code to connect to MySQL cannot succeed
  • The function used by the program to connect to MySQL ismysql_real_connect()

Second, the error message

Can't connect to local MySQL server through socket '/tmp/mysql.sock' (111)

Three, tried methods

The solutions in these links below cannot solve my problem :

method link
Modify the my.cnf file mysql remotely connect to the database report 111 error
Delete the mysql.sock file Can't connect to local MySQL server through socket'/var/lib/mysql/mysql.sock' (111)
Add cache swap Can’t connect to local MySQL server through socket ‘/var/lib/mysql/mysql.sock’ (111)
Modify the connection pool in the my.cnf file mysql: Can't connect to local MySQL server through socket'/var/lib/mysql/mysql.sock' (111) error resolution
Restart only mysql connection error ERROR 2002 (HY000): Can't connect to local MySQL server through socket...

Fourth, the way to success

Five, the cause of the problem

localhostIt's through UNIX socketconnection; it
127.0.0.1's through TCP/IPconnection.


Important material

mysql common error codes

Guess you like

Origin blog.csdn.net/qq_29695701/article/details/104932042