Similar to Brunonono in Create MySQL Database in Python using the %s operator (even using the same packages) I'm trying to add columns from an excel table to a mysql table using the %s operator in Python. The error is the same:
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 %s)' at line 1
The code is as follows
mydb=mysql.connector.connect(host="localhost",user="root")
#init cursor
mycursor=mydb.cursor()
column_title="ID"
cell_type="INT(10)"
mycursor.execute("ALTER TABLE Test ADD (%s %s)"),(column_title, cell_type)
Sadly, I wouldn't know how to apply the solution provided in the post above, where
mycursor.execute("CREATE DATABASE (%s)", (db_name))
was replaced with
create_statement = "CREATE DATABASE {:s}".format(db_name)
mycursor.execute(create_statement)