使用标准脚本(或任何其他)我无法连接python到mysql。我目前拥有Conceptive Engineering(Python 2.7.2)的Python for Python。早些时候,我尝试从Enthought免费下载(也许分别添加mysqldb)。至于mysql,最新版本是应该自动正确安装的通用Windows下载(mysql-installer - 5.5.25a0.msi)。我尝试了MySQL 5.1,5.0之后没有一个大小的安装程序(有时在64位,有时32)。python mysql连接
在所有情况下,python和mysql都可以单独工作。我可以在尝试连接之前看到运行mysql的Windows服务。
主要脚本可以分解成两行:
#this one always works without error in ipython
import MySQLdb
#this one never works, though all the variables test out in mysql fine
con = MySQLdb.connect(host="localhost", port=3306, user="root", db="sakila")
这里是从IPython中
OperationalError Traceback (most recent call last)
C:\Program Files (x86)\PythonSDK\<ipython-input-3-1ffbd20d17a9> in <module>()
----> 1 con = MySQLdb.connect(host="localhost", port=3306, user="root", db="sakila")
C:\Program Files (x86)\PythonSDK\lib\site-packages\mysql_python-1.2.3-py2.7-win32.egg\MySQLdb\__init__.py in Connect(*args, **kwargs)
79 """Factory function for connections.Connection."""
80 from connections import Connection
---> 81 return Connection(*args, **kwargs)
82
83 connect = Connection = Connect
C:\Program Files (x86)\PythonSDK\lib\site-packages\mysql_python-1.2.3-py2.7-win32.egg\MySQLdb\connections.py in __init__(self, *args, **kwargs)
185 kwargs2['client_flag'] = client_flag
186
--> 187 super(Connection, self).__init__(*args, **kwargs2)
188
189 self.encoders = dict([ (k, v) for k, v in conv.items()
OperationalError: (2003, "Can't connect to MySQL server on 'localhost' (10061)")
嗯,密码? – Malvolio 2012-07-25 01:41:33
那么你可以成功地从命令行连接到MySQL? 'c:\ path \ to \ mysql \ bin \ mysql.exe -u root -p'并尝试了[建立Windows连接]的所有建议(http://dev.mysql.com/doc/refman/5.5/en/can-not-connect-to-server.html)上面最明显的省略是没有密码被传递给'MySQLdb.connect' – 2012-07-25 14:33:09
1.尝试了密码。 2.我已经成功地打开并使用了mysql,虽然没有通过上面的路径样式3.我并没有真正理解上面提到的所有建立的窗口连接。 – user1549323 2012-07-27 02:11:24