-1

我的来源

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

错误

Traceback (most recent call last):
  File "C:\Users\Jonathan\Desktop\python.py", line 20, 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 93, in Connect
    return Connection(*args, **kwargs)
  File "C:\Python33\lib\site-packages\pymysql\connections.py", line 510, in __init__
    self._connect()
  File "C:\Python33\lib\site-packages\pymysql\connections.py", line 658, in _connect
    sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
AttributeError: 'module' object has no attribute 'AF_UNIX'
>>> 
4

1 回答 1

5

如果您在 Windows 下,为什么要尝试使用 unix_socket 参数?

尝试:

conn = pymysql.connect(host='127.0.0.1', port=3306, user='user', passwd='', database='extractor')

于 2013-10-19T13:46:58.697 回答