尝试将 python 与 mysql 链接时出现错误
Posted
技术标签:
【中文标题】尝试将 python 与 mysql 链接时出现错误【英文标题】:I'm getting an error while trying to link python with mysql 【发布时间】:2021-11-29 17:37:32 【问题描述】:TypeError: __init__() takes 1 positional argument but 5 were given
这是错误,我将在下面分享脚本:
import pymysql
print('---DATABASE CONNECTION SAMPLE---')
x=pymysql.connect('localhost','root','sha@123','avodha')
cr=x.cursor()
cr.execute('create table student(name char(50),age int)')
x.close()
【问题讨论】:
connect
只接受关键字参数
【参考方案1】:
connect
不接受位置参数,它接受关键字参数:
x = pymysql.connect(host='localhost',
user='user',
password='passwd',
database='avodha')
【讨论】:
我试过了,它显示的语法无效 谢谢语法错误是我这边的一个错误,我得到了它的工作以上是关于尝试将 python 与 mysql 链接时出现错误的主要内容,如果未能解决你的问题,请参考以下文章