0

I know there're similar questions regarding this topic in Stackoverflow, like these ones:

But i still encounter an error passing a variable at moment execute is run.

Option #1

mycursor = mydb.cursor()
dbname = 'ssl'
mycursor.execute('CREATE DATABASE {}'.format(dbname))

And I get 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 'ssl' at line 1

Option 2

mycursor = mydb.cursor()
dbname = 'ssl'
mycursor.execute("CREATE DATABASE %s ", (dbname))

Getting similar 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

Any idea why?

11
  • try this mycursor.execute("CREATE DATABASE %(db)s ", {"db": db_name,}) Commented Jul 13, 2020 at 22:26
  • perhaps missing semicolon? CREATE DATABASE db_name;? Commented Jul 13, 2020 at 22:26
  • have you checked it dbname is actually set with anything? Commented Jul 13, 2020 at 22:30
  • @BoykeFerdinandes mycursor.execute("CREATE DATABASE %(db)s ", {"db": dbname,}) is giving the same 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 ''ssl'' at line 1 Commented Jul 13, 2020 at 22:30
  • @nbk it's. Even in the error appears ssl Commented Jul 13, 2020 at 22:31

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.