这是我从一些数据读入MySql的代码,Mysql表包含3列,在其中一列中我想插入数组的项目,每个项目插入一个新行,并且我不想有重复行:
db = MySQLdb.connect("127.0.0.1", "root", "M0", "my", local_infile=True,use_unicode=True, charset="utf8")
cursor = db.cursor()
r=["2","3"]
params = ['?' for item in r]
sql="insert ignore into array (firt,last_name,arrays) values 'nina','sa',(%s);" % ','.join(params)
cursor.execute(sql,r)
db.commit();
db.close()
我已经研究过这篇文章 [1]还有!
但是,在它们两个上我都收到此错误:
_mysql_exceptions.ProgrammingError: not all arguments converted during string formatting
请问有什么建议吗?
最佳答案
为什么你不能迭代集合
r=set(["2","3"])
for item in r:
sql="insert ignore into array (firt,last_name,arrays) values 'nina','sa',({})".format(item)
cursor.execute(sql)
关于python - 从列表中读入MySql,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51791406/