MySQL Socket error resolution method

Source: Internet
Author: User
Tags socket error

[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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.