insert a Python list into a column in MySQL

2019-05-21 10:59发布

问题:

I have list and I want to enter each element of that list into associated indexed cells of a column in MYSQL using Python.

E.g

lst = [11,22,33,44,55,66]

MYSql column:

Data
11
22
33
44
55
66.

How can I achieve this.

回答1:

Following code will do the work:

values = [list([item]) for item in lst]
cursor.executemany(u'INSERT INTO `tbl`(`Data`)(%s)', values)