When using mysqldb in Python to connect to the database, the following error occurs:
Traceback (most recentCallLast ):
File "/home/monitor_user/servermonitor. py", line 206, in <module>
Serverlist = sqlquery (getmngconn (), "select B. db_name, A. ip_inside, A. Port from machine a inner join dbinfo B on B. machine_id = A. machine_id ")
File "/home/monitor_user/servermonitor. py", line 39, in getmngconn
ReturnMysqldb. Connect (host = 'localhost', user = 'Monitor _ user', passwd = 'Monitor. user', DB = 'dbmanage ')
File "build/bdist. linux-x86_64/egg/mysqldb/_ init _. py", line 81, in connect
File "build/bdist. linux-x86_64/egg/mysqldb/connections. py", line 187, in _ init __
_ Mysql_exceptions.operationalerror: (2002, "can't connect to local MySQL server through socket '/var/lib/MySQL. Sock' (2 )")
The reason is that I have adjusted the MySQL sock file to/tmp/MySQL. sock, so you must specify the sock path in mysqldb (this is not intelligent. What if I have many MySQL servers and the sock path of each server is different ?)
ReturnMysqldb. Connect (host ='Localhost', User ='User', Passwd ='User', DB ='Dbname', Unix_socket ='/Tmp/MySQL. Sock')
The unix_socket parameter specifies the path of the sock file.