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?

Diego
  • 916
  • 1
  • 13
  • 36
  • try this `mycursor.execute("CREATE DATABASE %(db)s ", {"db": db_name,})` – Boyke Ferdinandes Jul 13 '20 at 22:26
  • perhaps missing semicolon? `CREATE DATABASE db_name;`? – avloss Jul 13 '20 at 22:26
  • have you checked it dbname is actually set with anything? – nbk Jul 13 '20 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 ` – Diego Jul 13 '20 at 22:30
  • @nbk it's. Even in the error appears `ssl` – Diego Jul 13 '20 at 22:31
  • on my system HOAT and CI_PROJECT_NAME is not set as enviroment variables, so when you cheked that check the mysql connection if it throws an error – nbk Jul 13 '20 at 22:34
  • enviromental variable HOAT and CI_PROJECT_NAME have the value of ssl in my side – Diego Jul 13 '20 at 22:35
  • If I change the value to a normal name, gets the same error. `dbname = 'ssl' mycursor.execute("CREATE DATABASE %(db)s ", {"db": dbname,})` Getting 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` – Diego Jul 13 '20 at 22:37
  • then show us your connection string, i doubt that that this runs withouit error – nbk Jul 13 '20 at 22:37
  • see also the manula for ssl connections https://dev.mysql.com/doc/connector-python/en/connector-python-connectargs.html – nbk Jul 13 '20 at 22:39
  • @nbk looks like the problem is the value for `ssl` with `ssl1` works. Never thought about it. Thanks! – Diego Jul 13 '20 at 22:41

0 Answers0