Python和MySQL:如果遇到死锁错误,一切都会回滚吗?

时间:2015-12-09 20:48:05

标签: python mysql

我想捕获MySQL死锁错误,然后重试失败的查询。但是,自从事务开始以来,我是否必须重做每个查询,或者只是try / catch中的那个查询?我不确定死锁错误是否导致所有内容都被回滚。

这是使用原始mysql查询在Python中执行的。

insert into table_1 values...
insert_into_table_2 values ...
try:
   delete from table_1 where ...
except: # set to catch deadlock error
   # Can I just retry the delete statement, or do I also have to do the inserts again?

# commits at end

1 个答案:

答案 0 :(得分:0)