Getting connection error in PyMYSQL:
Error
conn = pymysql.connect(host='127.0.0.1', port=3306, user='root', passwd='', db='pymysql')
AttributeError: 'module' object has no attribute 'connect'
code
import pymysql
conn = pymysql.connect(host='127.0.0.1', port=3306, user='root', passwd='', db='pymysql')
cur = conn.cursor()
cur.execute("SELECT Host,User FROM user")
print(cur.description)
print()
for row in cur:
print(row)
cur.close()
conn.close()
Use capital 'C' in pymysql.Connect.
conn = pymysql.Connect(host='127.0.0.1', port=3306, user='root', passwd='', db='pymysql')
The above statement should work. It worked for me!
You've called some other module "pymysql". Look for a file named "pymysql.py" and rename it, and remove any associated .pyc file.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.