python - 尝试将 python 与 mysql 链接时出现错误
问题描述
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
不采用位置参数,它采用关键字参数:
x = pymysql.connect(host='localhost',
user='user',
password='passwd',
database='avodha')
推荐阅读
- sql - Spring Data JPA - 规范
- node.js - 如何使用 MongoDB 显示由“NAME”创建的
- linux - 如何在 shell 中遍历我的文本文档中的单词。我想在我的文本文档中显示字数
- react-admin - 如何在 AppBar 上设置配置显示/隐藏刷新按钮
- sql-server - MariaDB 和 Microsoft SQL Server 在同一台服务器上
- angular - Angular 6无限滚动(滚动)不起作用
- javascript - 从字面上看,画布另存为png
- ios - Swift 中的日志行号和方法名
- apache-spark - Spark Dataframe 复杂排序
- node.js - Reactjs 网络热敏打印机