我正在尝试连接python和mysql,但是当我键入代码import mysql.connector
时python返回无效的语法。我已经纠正了代码的所有其他部分,但这是我面临的唯一问题。我在下面给出了我的代码,该代码旨在将值插入到mysql表中
import mysql.connector
mycon=mysql.connector.connect(host="localhost",user="root",password="modern",database="mydatabase")
mycursor=mycon.cursor()
mycursor.execute("CREATE TABLE library_management(book_code integer auto_increment primary key,book_name varchar(800) issue_date date,due_date date)")
sql="insert into library_management(book_code,book_name) VALUES (%s,%s,%s)"
val=[
(21085501,"DIVERGENT'")
(21085502,'INSURGENT')
(21085503,'ALLEGIANT')
(21085504,'FOUR')
(21085591,"Harry potter and the philosopher's stone")
(21085592,"Harry potter and the chamber of secrets")
(21085593,"harry potter and the prisoner of azkaban")
(21085594,"harry potter and the goblet of fire")
(21085595,"harry potter and the order of the pheonix")
(21085596,"harry potter and the half blood prince")
(21085597,"harry potter and the death;y hallows")
(21085571,"the fault in our stars")
(20185572,'who will cry when you die')
(21085581,"angels and demons")
(21085582,"digital fortress")
(21085583,"the da vinci code")
(21085584,"deception point")
(21085585,"the lost symbol")]
mycursor.executemany(sql,val)