我正在尝试使用pymysql访问使用MySQL创建的数据库,但出现以下错误。有谁知道如何消除此错误?
Connection = pymysql.connect(host="localhost",db="Student",port=8000,
username="makotonakai",passwd="password")
TypeError: __init__() got an unexpected keyword argument 'username'
答案 0 :(得分:1)
试试这个:
import pymysql
conn = pymysql.connect(
host="127.0.0.1", port=8000, user="makotonakai", passwd="password", db="Student"
)
cursor = conn.cursor()
cursor.execute("SELECT VERSION()")
row = cursor.fetchone()
print("Server version:", row[0])
cursor.close()
conn.close()
答案 1 :(得分:0)
将username
更改为user
,将passwd
更改为password
。应该是
Connection = pymysql.connect(host="localhost",db="Student",port=8000,user="makotonakai",password="password")