Python连MySQL Error 2002: Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock'

Ubuntu 16 Xampp集成环境下,用python2.12 去连接MySQL (MariaDB),得到如2002的错误。

Error 2002: Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)
Traceback (most recent call last):
File "main.py", line 52, in
result = connect_db.select('table', conditional_query, '*')
File "/home/user1/code/mysql_helper.py", line 71, in select
self.__session.execute(query, values)

运行sudo find / -type s命令去找到本机所有的socket文件。
我自己的环境下,因为是xampp集成环境,所以socket文件在 /opt/lampp/var/mysql/mysql.sock 这个位置。
试图去改/etc/mysql/my.cnf里有关socket的配置,发现压根就不存在。死路。。。

正解在这里。
使用127.0.0.1 代替 localhost。

你可能感兴趣的:(Python连MySQL Error 2002: Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock')