import MySQLdb
import csv
mydb = MySQLdb.connect(host='localhost',user='root',passwd='root', db='kabir')
cursor = mydb.cursor()
data = csv.reader(file('data.csv'))
#cursor.execute('create table actors(name varchar(20),age integer)')
for row in data:
cursor.execute('INSERT INTO actors(name,age) VALUES(%s %s)' ,row)
mydb.commit()
cursor.close()
最佳答案
您没有在 %s 和 %s 之间指定逗号。将其更改为:
cursor.execute('INSERT INTO actors(name,age) VALUES(%s, %s)' ,row)
然后尝试..
关于python - 数据没有插入到我的表中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22906262/