MySQL服务器运行正常,但是我的python没有用MySQL-python lib连接mysql,为什么?
$ port installed
mysql55 @5.5.27_0 (active)
mysql55-server @5.5.27_0 (active)
mysql_select @0.1.2_0 (active)
显示表格OK ...
$ mysql -uroot -Dtest
mysql> SHOW TABLES;
Empty set (0.00 sec)
我的python安装
$ pip freeze
Django==1.4.1
MySQL-python==1.2.4b2
为什么呢?
$ python
Python 2.7.3 (default, Jul 30 2012, 16:41:43)
[GCC 4.2.1 Compatible Apple Clang 4.0 ((tags/Apple/clang-421.0.57))] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import MySQLdb
>>> db = MySQLdb.connect(host="localhost", port=3306, user="root", passwd="", db="test")
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "build/bdist.macosx-10.7-x86_64/egg/MySQLdb/__init__.py", line 81, in Connect
File "build/bdist.macosx-10.7-x86_64/egg/MySQLdb/connections.py", line 187, in __init__
_mysql_exceptions.OperationalError: (2002, "Can't connect to local MySQL server through socket '/opt/local/var/run/mysql55/mysqld.sock' (2)")
$ ll /opt/local/var/run/mysql55/mysqld.sock
ls: /opt/local/var/run/mysql55/mysqld.sock: No such file or directory