Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Restarting transaction in MySQL after deadlock

I am facing a deadlock in my MySQL. How can I configure MySQL to restart the transaction automatically when it encounters a deadlock?

like image 840
Ravi Sankar Raju Avatar asked Aug 03 '11 11:08

Ravi Sankar Raju


2 Answers

You cannot do that automatically, as the deadlock occurred, because two transactions were trying to modify the same data. If you know that simply retrying the same statements again will be the right thing to do, you need to implement this in your application.

However having the database do that automatically would be irresponsible, because there might just as well be cases where your application first needs to take a look at the new situation in the database, before issuing potentially modified statements, if any at all.

like image 118
Daniel Schneller Avatar answered Sep 20 '22 03:09

Daniel Schneller


Normally, you must write your applications so that they are always prepared to re-issue a transaction if it gets rolled back because of a deadlock.

http://dev.mysql.com/doc/refman/5.1/en/innodb-deadlocks.html

The manual suggests that no such configuration option exists.

like image 39
Dan Grossman Avatar answered Sep 22 '22 03:09

Dan Grossman