mysql.connector-您的SQL语法有错误;第1行的“%s"附近 [英] mysql.connector - You have an error in your SQL syntax; near '%s' at line 1

查看:70
本文介绍了mysql.connector-您的SQL语法有错误;第1行的“%s"附近的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我引用的是此页面以便对我的数据库进行SELECT查询.但是,我收到此错误:

I'm referencing this page in order to make a SELECT query to my database. However, I'm getting this error:

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

这是有问题的代码部分:

Here's the section of code with the problem:

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'也可以.

Notes:
- When doing an INSERT query with %s it works.
- Also, replacing %s with 'testuser123' works.

推荐答案

您缺少使用逗号分隔userAuthInfo元组的逗号.将其更改为:

You are missing the comma to make userAuthInfo a tuple. Change it to :

userAuthInfo = (givenUsername,)

这篇关于mysql.connector-您的SQL语法有错误;第1行的“%s"附近的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆