Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

mysql.connector - You have an error in your SQL syntax; near '%s' at line 1 [closed]

Tags:

python

mysql

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)

# ...

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

like image 929
cid Avatar asked May 30 '17 16:05

cid


People also ask

Why am I getting a MySQL Connector/ODBC error?

This error may be related to Keyboard Logger 1.1 from PanteraSoft.com, which is known to interfere with the network communication between MySQL Connector/ODBC and MySQL. When using some applications to access a MySQL server using Connector/ODBC and outer joins, an error is reported regarding the Outer Join Escape Sequence.

Why can't I connect to my local MySQL server?

This error can be raised by a number of different issues, including server problems, network problems, and firewall and port blocking problems. For more information, see Can't connect to [local] MySQL server . The following error is reported when using transactions: Transactions are not enabled

What is a MySQL 1064 error?

Let’s get started! The MySQL 1064 error is a syntax error. This means the reason there’s a problem is because MySQL doesn’t understand what you’re asking it to do.

Why am I getting a MySQL error when trying to use transactions?

This error indicates that you are trying to use transactions with a MySQL table that does not support transactions. Transactions are supported within MySQL when using the InnoDB database engine, which is the default storage engine in MySQL 5.5 and higher. In versions of MySQL before MySQL 5.1, you may also use the BDB engine.


1 Answers

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

userAuthInfo = (givenUsername,)
like image 134
Alasdair Avatar answered Oct 11 '22 09:10

Alasdair