【问题标题】:I'm getting an error while trying to link python with mysql尝试将 python 与 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 只接受关键字参数

标签: python mysql typeerror pymysql


【解决方案1】:

connect 不接受位置参数,它接受关键字参数:

x = pymysql.connect(host='localhost',
                    user='user',
                    password='passwd',
                    database='avodha')

【讨论】:

  • 我试过了,它显示的语法无效
  • 谢谢语法错误是我这边的一个错误,我得到了它的工作
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2012-01-15
  • 2012-06-22
  • 1970-01-01
  • 1970-01-01
  • 2012-04-20
  • 1970-01-01
相关资源
最近更新 更多