Windows上的Python 3.3.2 - MysqlDB& pymysql

时间:2013-10-19 11:27:41

标签: python mysql ssh mysql-python

我在Windows 8上使用Python 3.3.2,尝试通过已经运行的ssh(putty)在线连接到mysql

我尝试使用

安装mysqldb
pip install MySQL-python

但是我得到了LOG

使用此代码安装后尝试使用pymyqslafter进行连接时

conn = pymysql.connect(host='127.0.0.1', unix_socket='/tmp/mysql.sock', user='bitnami', passwd=None, db='extractor')
cur = conn.cursor()
cur.execute("SELECT * FROM eaexpress")
for response in cur:
    print(response)
cur.close()
conn.close()

我收到此错误:

Traceback (most recent call last):
File "C:\Python33\lib\site-packages\pymysql\connections.py", line 780, in _connect
sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
AttributeError: 'module' object has no attribute 'AF_UNIX'

在处理上述异常期间,发生了另一个异常:

Traceback (most recent call last):
File "C:\Users\Jonathan\Desktop\python.py", line 19, in <module>
    conn = pymysql.connect(host='127.0.0.1', unix_socket='/tmp/mysql.sock', user='bitnami', passwd=None, db='extractor')

File "C:\Python33\lib\site-packages\pymysql\__init__.py", line 88, in Connect
    return Connection(*args, **kwargs)

File "C:\Python33\lib\site-packages\pymysql\connections.py", line 634, in __init__
    self._connect()
File "C:\Python33\lib\site-packages\pymysql\connections.py", line 818, in _connect
    2003, "Can't connect to MySQL server on %r (%s)" % (self.host, e))
pymysql.err.OperationalError: (2003, "Can't connect to MySQL server on '127.0.0.1' ('module' object has no attribute 'AF_UNIX')")
 >>> 

我通过ssh连接到myphpadmin,它在浏览器上运行良好。除非有一种方法让python使用openssh或ppk文件进行连接而不需要ssh,否则在此之前会更好。我必须解决这些问题。

在我的服务器上连接mysql有什么建议吗?

1 个答案:

答案 0 :(得分:3)

Python扩展程序包非官方Windows二进制文件的大量列表,对Windows用户非常有用。

http://www.lfd.uci.edu/~gohlke/pythonlibs/

转到链接并搜索 MySQL-python 并安装它,你就可以了。

干杯!