Python MySQLdb编程错误:插入数据时出现1064
我有这个清单Python MySQLdb编程错误:插入数据时出现1064,python,sql,mysql-python,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.cu
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")
match是varchar(150),tournamentname是varchar(150),matchdate是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)
将第四行修改为:
query = "INSERT INTO todaysmatches (`match`,`tournamentname`,`matchdate`) VALUES (%s,%s,%s)"
哦,是的<代码>2014年2月26日应为
2014年2月26日
。