在多个事务之间使用单个MySQLdb连接而不关闭连接是否可行?换句话说,类似于这样的内容:
conn = MySQLdb.connect(host="1.2.3.4", port=1234, user="root", passwd="x", db="test")
for i in range(10):
try:
cur = conn.cursor()
query = "DELETE FROM SomeTable WHERE ID = %d" % i
cur.execute(query)
cur.close()
conn.commit()
except Exception:
conn.rollback()
conn.close()
看起来工作正常,但我想再确认一下。