Skip to content

Instantly share code, notes, and snippets.

@pgr0ss
Created October 19, 2012 05:41
Show Gist options
  • Save pgr0ss/3916412 to your computer and use it in GitHub Desktop.
Save pgr0ss/3916412 to your computer and use it in GitHub Desktop.
MySQL Deadlock
CREATE TABLE foo (id INT) ENGINE INNODB;
-- session 1 session 2
------------------------------------------------------------------------
BEGIN;
------------------------------------------------------------------------
BEGIN;
------------------------------------------------------------------------
INSERT INTO foo VALUES (1);
------------------------------------------------------------------------
INSERT INTO foo VALUES (2);
------------------------------------------------------------------------
UPDATE foo SET id = 2 WHERE id = 1;
------------------------------------------------------------------------
UPDATE foo SET id = 4 WHERE id = 2;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment