死锁的一个例子

先执行第一段

begin;

update tb set name = 222 where id = 1;

select sleep(5);

update stu set name = 333 where id = 1;

commit;

紧接着执行第二段

begin;

update stu set name = 444 where id = 1;

select sleep(5);

update tb set name = 555 where id = 1;

commit;

过一会第二段会提示错误。

 第一段会顺利执行完成,这是因为第一段先执行,第二段执行到update tb set name = 555 where id = 1时,一段已经在等待二段释放了行了,这时二段再来等待一段,就形成了死锁,二段被终止了执行。

posted @ 2017-10-11 16:18  wahgon  阅读(217)  评论(0编辑  收藏  举报