简体   繁体   English

使用 Python 操作 MySQL 数据库时出现 1064 错误

[英]1064 error while operating MySQL database with Python

I want to write a program in Python to control MySQL database, but the following error occurs我想用Python写一个程序来控制MySQL数据库,但是出现如下错误

pymysql.err.ProgrammingError: (1064, "You have an error in your SQL syntax; chec
k the manual that corresponds to your MySQL server version for the right syntax
to use near 'Code,type, number,Whether )VALUES ('cl8k-k520-fg45-d4sa-sd9k','n' at line 1")

Code:代码:

import pymysql 
db = pymysql.connect("localhost", "root", "root", "test")
cursor = db.cursor()
sql = "INSERT INTO BOOKS(Activation Code, \
       type, number,Whether ) \
       VALUES (%s,%s,%s,%s)"
data = [("cl8k-k520-fg45-d4sa-sd9k",'n','10','n'),
        ("jhg6-58jh-gh8o-8uik-7jk8",'c','20','n'),
        ("x5hg-gf5h-4hj5-g4h5-fh5t",'y','999','n'),
        ("fg8j-h584-fd4g-fg4d-fgg4",'n','1','y'),
        ("4jk4-5kl4-4klk-4lji-4ghj",'e','6','n'),
        ]
cursor.executemany(sql,data)
db.close()

This is my first time to ask questions on this platform.这是我第一次在这个平台上提问。 I hope to get answers我希望得到答案

Activation Code作为'Activation Code'括起来

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM