Skip to content

Instantly share code, notes, and snippets.

@teddy-hoo
Created May 8, 2017 12:42
Show Gist options
  • Select an option

  • Save teddy-hoo/5b45a98c5b5b259cef363610253405c7 to your computer and use it in GitHub Desktop.

Select an option

Save teddy-hoo/5b45a98c5b5b259cef363610253405c7 to your computer and use it in GitHub Desktop.
reproduce a deadlock in mysql
# session 1
use test;
create table t (i int) engine = InnoDB;
insert into t(i) values(1);
start transaction;
select * from t where i = 1 lock in share mode;
# session 2
use test;
start transaction;
delete from t where i = 1;
# session 1
delete from t where i = 1;
# session 1 output
Query OK, 1 row affected (0.02 sec)
# session 2 output
ERROR 1213 (40001): Deadlock found when trying to get lock; try restarting taction
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment