我引用this page以便对我的数据库进行SELECT查询。但是,我收到了这个错误:
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 '%s' at line 1
以下是带有问题的代码部分:
import mysql.connector
cnx = mysql.connector.connect(user='xxxx', password='yyyy',
host='zzzz.us-west-2.rds.amazonaws.com',
database='iiii')
cursor = cnx.cursor()
# ...
givenUsername = 'testUser123'
checkUserAuthQuery = ("SELECT password FROM UserAuth WHERE username = %s")
userAuthInfo = (givenUsername)
cursor.execute(checkUserAuthQuery, userAuthInfo)
# ...
备注:
- 使用%s
进行INSERT查询时,它可以正常工作
- 另外,将%s
替换为'testuser123'
有效。
答案 0 :(得分:7)
您缺少使逗号userAuthInfo
成为元组的逗号。将其更改为:
userAuthInfo = (givenUsername,)