TypeError:__init __()在pymysql中获得了意外的关键字参数'username'

时间:2018-09-27 02:06:59

标签: pymysql

我正在尝试使用pymysql访问使用MySQL创建的数据库,但出现以下错误。有谁知道如何消除此错误?

Connection = pymysql.connect(host="localhost",db="Student",port=8000,
username="makotonakai",passwd="password")

TypeError: __init__() got an unexpected keyword argument 'username'

2 个答案:

答案 0 :(得分:1)

试试这个:

  • 端口 3306 是经典 MySQL 协议的默认端口
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")