我正在尝试从MySQL数据库中检索数据。
A = "James"
query = ("SELECT * FROM DB.tblusers WHERE UserName = %s ")
c = mysql.connector.connect(user='root', password='',
host='127.0.0.1',
database='DB')
cur1 = c.cursor()
cur1.execute(query, A)
给出以下错误消息:
mysql.connector.errors.ProgrammingError: 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 '%' at line 1
但SQL可以在mySQL Workbench中运行。 有什么想法吗?
答案 0 :(得分:17)
A
应该是一个元组,请尝试使用A = ("James",)
请参阅MySQLCursor.execute(operation, params=None, multi=False)
的文档