Python MySQLdb编程错误: 1064 when inserting data

标签 python sql mysql-python

我有这个列表

info=[[u' Rasta.eon 2 - 1 Rasta.Xd   ', u'Razer CS:GO Tournament 2', u'26-02-2014'], [u' XPC 1       - 2 WP.GG  ', u'Roccat DotA 2 Tournament', u'26-02-2014']]

conn= MySQLdb.connect(host='localhost',user='root',passwd='',db='ee')

c = conn.cursor()
query = "INSERT INTO todaysmatches (match,tournamentname,matchdate) VALUES (%s,%s,%s)"
c.executemany(query, info)
conn.commit()
conn.close()

当我尝试执行查询时出现此错误

ProgrammingError: (1064, "You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'match,tournamentname,matchdate) VALUES \n(' Rasta.eon 2 - 1 Rasta.Xd   ','Razer C' at line 1")

比赛是 varchar(150),比赛名称是 varchar(150),比赛日期是 DATE

最佳答案

match 是 MySQL 中的关键字。如果反引号,您可以将其用作列名

INSERT INTO todaysmatches (`match`,tournamentname,matchdate) VALUES (%s,%s,%s)

但如果您为该列选择其他名称会更方便。


看看当您尝试创建一个包含名为 match 的列的表时会发生什么:

mysql> create table foo (match varchar(150), tournamentname varchar(150), matchdate DATE);
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'match varchar(150), tournamentname varchar(150), matchdate DATE)' at line 1
mysql> create table foo (`match` varchar(150), tournamentname varchar(150), matchdate DATE);
Query OK, 0 rows affected (0.03 sec)

关于Python MySQLdb编程错误: 1064 when inserting data,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22226488/

相关文章:

mysql - 在临时表中使用 where 子句

python - 更改密码,python,linux

python - 在循环中使用 find_peaks 从数据中查找峰值高度

python - 将列表中的 str 元素耦合到元组列表

mysql - 而不是 MySQL ORDER BY RAND

linux - 安装 MYSQLdb 没有错误,但我无法导入

python - 在装饰器内部使用部分时 self 丢失

sql - 对象结构关系数据库设计

python - 更新 MySQL 字段的行

Python 3.7,MySql-Python 的构建轮失败