将Python变量值插入MySql表

时间:2018-01-12 15:08:17

标签: python mysql python-3.x mysql-connector mysql-connector-python

使用MySql连接器和Python时,如何将Python变量值插入MySql表?

示例:

data = 5

cursor.execute("""INSERT INTO table1 VALUES ( data )""")

我想将'data'的值插入表名'table1'

1 个答案:

答案 0 :(得分:0)

data = 5
cursor.execute("INSERT INTO table1 VALUES ( ?)", (data,))