search

Home  >  Q&A  >  body text

windows - 用python3的pymysql库连接mysql时出现AttributeError

刚开始学用python整合mysql,代码如下

import pymysql

conn = pymysql.connect(host='127.0.0.1',unix_socket='/tmp/mysql.sock',user='zzp',password='zaqwsx123',db='mysql')
cur = conn.cursor()
cur.execute('USE scraping')
cur.execute('SELECT * FORM pages WHERE id = 1')
print(cur.fetchone())
cur.close()
conn.close()

百度时有人说删除socket.pyc文件,但我没找到什么socket.pyc文件
有人说是命名冲突。但具体的解决办法是什么呢?

PHP中文网PHP中文网2811 days ago651

reply all(1)I'll reply

  • 天蓬老师

    天蓬老师2017-04-18 10:13:56

    Looking at your error message, I know that the environment you are running in is Windows, but the conn written in your py code is the connection method of the Linux server, and it is also a socket connection

    reply
    0
  • Cancelreply