如何在MySQL上造成死锁 [英] How to cause deadlock on MySQL

查看:120
本文介绍了如何在MySQL上造成死锁的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

出于测试目的,我需要在 MySQL 上生成"1213:死锁" ,以便UPDATE查询无法更新表.

For test purposes, I need to generate a "1213: Deadlock" on MySQL so that UPDATE query can't update a table.

我不太确定如何导致死锁?

I am not not quite sure how to cause deadlock?

推荐答案

有很多使用两个会话的帖子.

There are numerous posts for this by using two sessions.

https://dba.stackexchange.com/questions/309/code-to-simulate -死锁

http://www.xaprb.com/blog/2006/08/08/how-to-deliberately-cause-a-deadlock-in-mysql/

方法是从上面的第二篇文章中复制的

首先,选择一个未使用的表名.我将使用test.innodb_deadlock_maker.这是您需要执行的语句:

First, choose an unused table name. I’ll use test.innodb_deadlock_maker. Here are the statements you need to execute:

create table test.innodb_deadlock_maker(a int primary key) engine=innodb;
insert into test.innodb_deadlock_maker(a) values(0), (1);

现在,已建立表格及其数据.接下来,在两个不同的连接上执行以下操作:

Now the table and its data are set up. Next, execute the following on two different connections:

-连接0

set transaction isolation level serializable;
start transaction;
select * from test.innodb_deadlock_maker where a = 0;
update test.innodb_deadlock_maker set a = 0 where a <> 0;

-连接1

set transaction isolation level serializable;
start transaction;
select * from test.innodb_deadlock_maker where a = 1;
update test.innodb_deadlock_maker set a = 1 where a <> 1;

这篇关于如何在MySQL上造成死锁的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆