[email protected] python]# python test.py slave_status
Traceback (most recent):
File "test.py", line +, in <module>
con = mysql.connect (user= ' Zabbix ', passwd= ', port=3306)
File "/usr/local/lib/python2.7/site-packages/mysqldb/__init__.py", line Bayi, in Connect
Return Connection (*args, **kwargs)
File "/usr/local/lib/python2.7/site-packages/mysqldb/connections.py", line 193, in __init__
Super (Connection, self). __init__ (*args, **KWARGS2)
_mysql_exceptions. Operationalerror: (2002, "Can ' t connect to local MySQL server through socket '/var/lib/mysql/mysql.sock ' (2)")
Look, my/etc/my.cnf, socket set is,/tmp/mysql.sock, I changed the project to/var/lib/mysql/mysql.sock, has been resolved.
[Email protected] python]# VIM/ETC/MY.CNF
Socket =/var/lib/mysql/mysql.sock
If you still have an error, it should be a matter of authority.
Or: Ln-s/var/lib/mysql/mysql.sock
It is important to note that I have not understood the role of the Mysql.sock file before, but I understand it today.
Here are the explanations I found on the Internet:
There are two ways to connect MySQL:
(1), TCP/IP
(2), socket
For Mysql.sock, the function is that the program is in the same machine as the MySQLServer and is available when the local connection is initiated.
For example, you do not need to define a specific IP to connect to the host, as long as it is empty or localhost.
In this case, even if you change the external port of MySQL It is also possible to connect normally.
Since you changed the port in My.ini or MY.CNF, the Mysql.sock is generated with every MySQL server startup. The information has been changed since you restarted MySQL when you finished changing the my.cnf.
Then for an external connection, you must change the port to connect.
MySQL Socket error resolution method