python - 数据没有插入到我的表中

标签 python mysql csv

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/

相关文章:

mysql - 1215 无法添加外键约束

CSV Helper 多个相同的列名称

python - Matplotlib Pyplot 条形图中的 float 条形

python - 将变量与数字相乘时遇到问题

mysql - Laravel 5 Connection.php 中的 QueryException 第 673 行 :

c# - MySQL 字段在 LOAD DATA LOCAL INFILE 后从 VARCHAR(20) 更改为 INT

java - supercsv如何通过列名获取列值数组

python - Mandelbrot 序列与 Python 的 Turtle

python - 在字符串列表中搜索的高效且最快的方法

mysql - 对连接数据进行排序