MySQLdbexecutemany不添加数据

hoo*_*ted 4 python mysql mysql-python

我正在尝试使用 MySQLdbexecutemany 命令将数据添加到表(test_copy),如下所示:

db = mdb.connect(host="127.0.0.1",port=3306,user='XXXX',db="test")
cursor = db.cursor()
COM = "insert into test_copy (Short_Model) VALUES (%s)"
VALS = ['213','3232','fd','sadad']
cursor.executemany(COM,VALS)
cursor.close
Run Code Online (Sandbox Code Playgroud)

注意:表名称 = test_copy,列名称 = Short_Model

问题是该命令运行时没有任何错误,但当我检查表时没有添加数据。

如果这是一个简单的问题,我深表歉意,但在过去的几个小时里它让我发疯。

谢谢。

hoo*_*ted 5

谢谢@Jon Clements 和@Abhishek Mishra - 你们让我恢复了理智。对于感兴趣的人来说,这是最终的解决方案:

db = mdb.connect(host="127.0.0.1",port=3306,user='xxxx',db="test")
cursor = db.cursor()
COM = "insert into test_copy (Short_Model) VALUES (%s)"
VALS = ['213','3232','fd','sadad']
cursor.executemany(COM,VALS)
db.commit()
Run Code Online (Sandbox Code Playgroud)