2013-10-19 73 views
-1

我的源的Python pymysql連接到MySQL在Windows

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' 
>>> 

回答

5

如果你是在Windows下,爲什麼你想使用unix_socket參數?

嘗試:

康恩= pymysql.connect(主機= '127.0.0.1',端口= 3306,用戶= '用戶',的passwd = '',數據庫= '提取')