使用標準腳本(或任何其他)我無法連接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