Skip to content
Advertisement

Python return error when trying to send a MySQL query that contains MySQL variables

I am trying to retrieve data from a MySQL database by sending a MySQL query using Python.

When I send the MySQL Query in MySQL workbench, it runs perfectly fine.

When I try the same using Python (in a Jupyter Notebook), it returns an error.

Python Code:

Error:

If I remove the variable in the MySQL Query it runs fine:

What am I doing wrong?


Final Solution:

Thank you Prashant Sharma for the solution.

I tweaked it a bit so it returns a pandas dataframe and allows for a list of variables to be passed prior to the Select query.

Here is the code:

Advertisement

Answer

The below code does the job, have tested it. You might have to rectify some indentation issue incase if something pops up.

User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement