Python 用数组值替换mysql insert语句

Python 用数组值替换mysql insert语句,python,mysql,linux,Python,Mysql,Linux,我正在尝试使用数组值列表为MySQL执行insert语句,但没有成功 我的“数组”列表具有所有必需的值 insert_statement = "insert into db (Hostname,Serial_Number,cpu,memory,Eth0_IP,Eth1_IP,hardware_type,datacenter,Operating_System) values ('%s','%s','%s','%s','%s','%s','%s','%s','%s') % (array[0], ar

我正在尝试使用数组值列表为MySQL执行insert语句,但没有成功

我的“数组”列表具有所有必需的值

insert_statement = "insert into db (Hostname,Serial_Number,cpu,memory,Eth0_IP,Eth1_IP,hardware_type,datacenter,Operating_System) values ('%s','%s','%s','%s','%s','%s','%s','%s','%s') % (array[0], array[1], array[2], array[3], array[4], array[5], array[6], array[7], array[8])"

cur.execute(insert_statement)
我也试过了

insert_statement = "insert into db (Hostname,Serial_Number,cpu,memory,Eth0_IP,Eth1_IP,hardware_type,datacenter,Operating_System) values ('%s','%s','%s','%s','%s','%s','%s','%s','%s') , array"

cur.executemany(insert_statement)

两者都出现了“sql语句错误”。

对于MySQLdb,这应该可以工作(如果您的数组由9个元素组成):


在插入变量值之后和执行之前,您可以发布什么样的
insert\u语句吗?您使用哪个MySQL模块_mysql?你在做百分比插值,这是不,不,你在查询中使用它。请在不带任何
%
insert\u语句中执行查询,然后执行
cur.execute(insert\u语句,数组)
insert_statement = "insert into db (Hostname,Serial_Number,cpu,memory,Eth0_IP,Eth1_IP,hardware_type,datacenter,Operating_System) values (%s,%s,%s,%s,%s,%s,%s,%s,%s)"

cur.execute(insert_statement, array)