重複の可能性:
Python: MySQLdb 接続の問題
MySQL サーバーは正常に動作していますが、私の python は mysql で MySQL-python lib に接続していません。なぜですか?
$ 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