【发布时间】:2010-05-30 21:25:36
【问题描述】:
当我尝试使用 MySQLPython(通过 SQLAlchemy)时出现错误
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/MySQL_python-1.2.3c1-py2.6-macosx-10.6-x86_64.egg/MySQLdb/connections.py", line 188, in __init__
super(Connection, self).__init__(*args, **kwargs2)
sqlalchemy.exc.OperationalError: (OperationalError) (2002, "Can't connect to local MySQL server through socket '/opt/local/var/run/mysql5/mysqld.sock' (2)") None None
但我的机器上没有其他 mysql 客户端可以正常运行!
我的 my.cnf 文件状态:
[client]
port = 3306
socket = /tmp/mysql/mysql.sock
[safe_mysqld]
socket = /tmp/mysql/mysql.sock
[mysqld_safe]
socket = /tmp/mysql/mysql.sock
[mysqld]
socket = /tmp/mysql/mysql.sock
port = 3306
mysql.sock 文件确实位于 /tmp/mysql
我确认 ~/.my.cnf 和 /var/lib/mysql/my.cnf 没有覆盖它。 mysql5客户端程序等连接没有问题,使用jdbc/mysql连接在同一台机器上安装groovy/grails也没有
thrilllap-2:~ swirsky$ mysql5
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 6
Server version: 5.1.47 Source distribution
Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.
This software comes with ABSOLUTELY NO WARRANTY. This is free software,
and you are welcome to modify and redistribute it under the GPL v2 license
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| test |
+--------------------+
2 rows in set (0.00 sec)
mysql>
为什么 MySQLdb for python 不能解决这个问题?如果不是 my.cnf 文件,它会在哪里查看?
【问题讨论】: