mysql死锁实例_MySql一个生产死锁案例分析

MySql--死锁 接着,事务B也尝试更新第一行记录,但是由于事务A还未提交,第一行记录被锁住。当发生死锁时,MySQL会自动选择其中一个事务作为死锁的牺牲者,回滚该事务,并释放锁定的资源,从而解除死锁。MySQL会检测到死锁的情况,并自动选择一个事务作为死锁的牺牲者,将其回滚以解决死锁问题。MySQL死锁是指多个事务同时持有不同的资源,并且互相请求对方的资源,导致无法继续进行下去的情况。重试机制:当捕捉到死锁错误时,可以在代码中添加重试机制,即重新执行被阻塞的事务,直到没有死锁发生为止。一、什么是mysql死锁? 阅读详情

接到上级一个生产环境MySQL死锁日志信息文件,需要找出原因并解决问题。我将死锁日志部分贴出如下:

在mysql中使用命令:SHOW ENGINE INNODB STATUS;总能获取到最近一些问题信息,通过搜索deadlock 关键字即可找到死锁的相关日志信息。

2019-09-25 13:28:25 7fc0301ca700InnoDB: transactions deadlock detected, dumping detailed information.

2019-09-25 13:28:25 7fc0301ca700

*** (1) TRANSACTION:

TRANSACTION 48000896642, ACTIVE 0 sec starting index read

mysql tables in use 1, locked 1

LOCK WAIT 5 lock struct(s), heap size 1184, 3 row lock(s), undo log entries 5

MySQL thread id 1585229, OS thread handle 0x7fc030e7c700, query id 36142536228 100.64.177.170 oms8 updating

update tb_elc_forecast

set capital = capital - 1.0, outbound = outbound + 1.0

where id = 1131766 and capital >= 1.0

*** (1) WAITING FOR THIS LOCK TO BE GRANTED:

RECORD LOCKS space id 1697 page no 31889 n bits 120 index `PRIMARY` of table `oms8`.`tb_elc_forecast` trx id 48000896642 lock_mode X locks rec but not gap waiting

Record lock, heap no 20 PHYSICAL RECORD: n_fields 46; compact format; info bits 0

0: len 4; hex 801144f6; asc D ;;

1: len 6; hex 000b2d138e83; asc - ;;

2: len 7; hex 1b0013b0a9145c; asc \;;

3: len 30; hex 3637666533626536382d616562622d313165392d393838332d6436636337; asc 67fe3be68-aebb-11e9-9883-d6cc7; (total 37 bytes);

4: len 10; hex 4d324c50303530303030; asc M2LP050000;;

5: len 11; hex 5730323130313439393137; asc W0210149917;;

6: len 4; hex 20bcbe4c; asc L;;

7: len 4; hex 000080bf; asc ;;

8: len 4; hex 006e2f47; asc n/G;;

9: len 4; hex 005c5646; asc \VF;;

10: len 4; hex 00000000; asc ;;

11: len 7; hex 323031392d3039; asc 2019-09;;

12: len 9; hex 4252414e4453495445; asc BRANDSITE;;

13: len 14; hex 776d735f656c635f62616f7a756e; asc wms_elc_baozun;;

14: len 4; hex 80000002; asc ;;

15: len 4; hex 80000001; asc ;;

16: len 4; hex 80000000; asc ;;

17: len 5; hex 99a3b313ab; asc ;;

18: SQL NULL;

19: len 3; hex 737973; asc sys;;

20: SQL NULL;

21: len 4; hex 80019737; asc 7;;

22: SQL NULL;

23: SQL NULL;

24: SQL NULL;

25: SQL NULL;

26: SQL NULL;

27: len 2; hex 3130; asc 10;;

28: len 12; hex 4252414e44534954455f3130; asc BRANDSITE_10;;

29: SQL NULL;

30: len 30; hex 494c4c554d494e4154494e4720464143452042415345205320374d4c2f2e; asc ILLUMINATING FACE BASE S 7ML/.; (total 88 bytes);

31: len 9; hex 4252414e4453495445; asc BRANDSITE;;

32: len 1; hex 59; asc Y;;

33: len 1; hex 59; asc Y;;

34: len 4; hex 80000000; asc ;;

35: len 0; hex ; asc ;;

36: len 4; hex 00000000; asc ;;

37: len 4; hex 00000000; asc ;;

38: len 4; hex 80000000; asc ;;

39: len 4; hex 80000000; asc ;;

40: SQL NULL;

41: SQL NULL;

42: len 4; hex 00000000; asc ;;

43: len 4; hex 00000000; asc ;;

44: SQL NULL;

45: SQL NULL;

*** (2) TRANSACTION:

TRANSACTION 48000896643, ACTIVE 0 sec starting index read

mysql tables in use 1, locked 1

4 lock struct(s), heap size 1184, 2 row lock(s), undo log entries 3

MySQL thread id 1584766, OS thread handle 0x7fc0301ca700, query id 36142536229 100.64.177.168 oms8 updating

update tb_elc_forecast

set capital = capital - 1.0, outbound = outbound + 1.0

where id = 1164727 and capital >= 1.0

*** (2) HOLDS THE LOCK(S):

RECORD LOCKS space id 1697 page no 31889 n bits 120 index `PRIMARY` of table `oms8`.`tb_elc_forecast` trx id 48000896643 lock_mode X locks rec but not gap

Record lock, heap no 20 PHYSICAL RECORD: n_fields 46; compact format; info bits 0

0: len 4; hex 801144f6; asc D ;;

1: len 6; hex 000b2d138e83; asc - ;;

2: len 7; hex 1b0013b0a9145c; asc \;;

3: len 30; hex 3637666533626536382d616562622d313165392d393838332d6436636337; asc 67fe3be68-aebb-11e9-9883-d6cc7; (total 37 bytes);

4: len 10; hex 4d324c50303530303030; asc M2LP050000;;

5: len 11; hex 5730323130313439393137; asc W0210149917;;

6: len 4; hex 20bcbe4c; asc L;;

7: len 4; hex 000080bf; asc ;;

8: len 4; hex 006e2f47; asc n/G;;

9: len 4; hex 005c5646; asc \VF;;

10: len 4; hex 00000000; asc ;;

11: len 7; hex 323031392d3039; asc 2019-09;;

12: len 9; hex 4252414e4453495445; asc BRANDSITE;;

13: len 14; hex 776d735f656c635f62616f7a756e; asc wms_elc_baozun;;

14: len 4; hex 80000002; asc ;;

15: len 4; hex 80000001; asc ;;

16: len 4; hex 80000000; asc ;;

17: len 5; hex 99a3b313ab; asc ;;

18: SQL NULL;

19: len 3; hex 737973; asc sys;;

20: SQL NULL;

21: len 4; hex 80019737; asc 7;;

22: SQL NULL;

23: SQL NULL;

24: SQL NULL;

25: SQL NULL;

26: SQL NULL;

27: len 2; hex 3130; asc 10;;

28: len 12; hex 4252414e44534954455f3130; asc BRANDSITE_10;;

29: SQL NULL;

30: len 30; hex 494c4c554d494e4154494e4720464143452042415345205320374d4c2f2e; asc ILLUMINATING FACE BASE S 7ML/.; (total 88 bytes);

31: len 9; hex 4252414e4453495445; asc BRANDSITE;;

32: len 1; hex 59; asc Y;;

33: len 1; hex 59; asc Y;;

34: len 4; hex 80000000; asc ;;

35: len 0; hex ; asc ;;

36: len 4; hex 00000000; asc ;;

37: len 4; hex 00000000; asc ;;

38: len 4; hex 80000000; asc ;;

39: len 4; hex 80000000; asc ;;

40: SQL NULL;

41: SQL NULL;

42: len 4; hex 00000000; asc ;;

43: len 4; hex 00000000; asc ;;

44: SQL NULL;

45: SQL NULL;

*** (2) WAITING FOR THIS LOCK TO BE GRANTED:

RECORD LOCKS space id 1697 page no 33024 n bits 120 index `PRIMARY` of table `oms8`.`tb_elc_forecast` trx id 48000896643 lock_mode X locks rec but not gap waiting

Record lock, heap no 5 PHYSICAL RECORD: n_fields 46; compact format; info bits 0

0: len 4; hex 8011c5b7; asc ;;

1: len 6; hex 000b2d138e82; asc - ;;

2: len 7; hex 1a0013b08b1598; asc ;;

3: len 30; hex 3638303365643664302d616562622d313165392d613830332d6436636337; asc 6803ed6d0-aebb-11e9-a803-d6cc7; (total 37 bytes);

4: len 10; hex 53383648343030303030; asc S86H400000;;

5: len 11; hex 5730323130313439393137; asc W0210149917;;

6: len 4; hex 20bcbe4c; asc L;;

7: len 4; hex 000080bf; asc ;;

8: len 4; hex 4001b448; asc @ H;;

9: len 4; hex 80c6de47; asc G;;

10: len 4; hex 00000000; asc ;;

11: len 7; hex 323031392d3039; asc 2019-09;;

12: len 9; hex 4252414e4453495445; asc BRANDSITE;;

13: len 14; hex 776d735f656c635f62616f7a756e; asc wms_elc_baozun;;

14: len 4; hex 80000002; asc ;;

15: len 4; hex 80000001; asc ;;

16: len 4; hex 80000000; asc ;;

17: len 5; hex 99a3b313b1; asc ;;

18: SQL NULL;

19: len 3; hex 737973; asc sys;;

20: SQL NULL;

21: len 4; hex 80019737; asc 7;;

22: SQL NULL;

23: SQL NULL;

24: SQL NULL;

25: SQL NULL;

26: SQL NULL;

27: len 2; hex 3130; asc 10;;

28: len 12; hex 4252414e44534954455f3130; asc BRANDSITE_10;;

29: SQL NULL;

30: len 30; hex 494c4c554d494e4154494e4720464143452042415345205320374d4c2f2e; asc ILLUMINATING FACE BASE S 7ML/.; (total 88 bytes);

31: len 9; hex 4252414e4453495445; asc BRANDSITE;;

32: len 1; hex 59; asc Y;;

33: len 1; hex 59; asc Y;;

34: len 4; hex 80000000; asc ;;

35: len 0; hex ; asc ;;

36: len 4; hex 00000000; asc ;;

37: len 4; hex 00000000; asc ;;

38: len 4; hex 80000000; asc ;;

39: len 4; hex 80000000; asc ;;

40: SQL NULL;

41: SQL NULL;

42: len 4; hex 00000000; asc ;;

43: len 4; hex 00000000; asc ;;

44: SQL NULL;

45: SQL NULL;

*** WE ROLL BACK TRANSACTION (2)

通过分析日志,我们知道如下信息:

1.发生死锁的两个事务中的SQL

事务1.updatetb_elc_forecastset capital = capital - 1.0, outbound = outbound + 1.0

where id = 1131766 and capital >= 1.0事务2.updatetb_elc_forecastset capital = capital - 1.0, outbound = outbound + 1.0

where id = 1164727 and capital >= 1.0

2.两条SQL都使用了Record lock(locks rec but not gap)记录锁(非间隙所)

通过查看表结构定义得知tb_elc_forecast将id字段定义为主键,表结构如下(精简版):

CREATE TABLE`tb_elc_forecast` (

`id`int(10) NOT NULL AUTO_INCREMENT COMMENT 'id自增',

`sku`varchar(50) NOT NULL COMMENT '商品',

`customerid`varchar(50) DEFAULT NULL COMMENT '货主',

`capital`float(10,2) DEFAULT '0.00' COMMENT '占用',

`outbound`float(10,2) DEFAULT '0.00' COMMENT '出库',PRIMARY KEY(`id`)

) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

通过以上信息,我们不难发现,肇事SQL会先对主键聚集索引加记录排他锁,而不是间隙锁。理论上好像怎么都不会产生死锁。因为这里只有一个临界资源,那就是聚集索引。从理论上来说,要发生死锁,必须存在至少两个临界资源,两个独立事务,且每个事务执行过程中相间执行,互锁对方需要的临界资源,从而导致死锁。示意图如下:

通过以上死锁理论理解分析,似乎光看这两个肇事SQL,不足以发生死锁的条件。那是为什么呢?我们不能孤立在这堆死锁日志里分析问题,应该去程序代码里找,找到肇事SQL所在的事务代码才行。这个死锁日志只是表达了发生死锁时涉事的两个SQL。并不一定能直接分析得出问题结论。

根据目前的情况,我做出如下假设:

1.事务A执行update tb_elc_forecast set capital = capital - 1.0, outbound = outbound + 1.0 where id = 1131766 and capital >= 1.0 前,id=1131766的记录被事务B查询了,加了共享锁在可重复读事务隔离级别下。同样事务B执行update tb_elc_forecast set capital = capital - 1.0, outbound = outbound + 1.0 where id = 1164727 and capital >= 1.0 前,id=1164727的记录被事务A查询了,加了共享锁在可重复读事务隔离级别下。最终两个事务的update语句无法获取id记录的排他锁导致死锁。

那么事情果真如此吗?通过模拟测试,结果是否定的。

事实上MySQL对于查询语句,只要查询完成就会释放共享锁,而不必等待事务结束,且和事务隔离级别无关。所以此种情况应该排除。

2.T1时刻事务A执行update tb_elc_forecast set capital = capital - 1.0, outbound = outbound + 1.0 where id = 1131766 and capital >= 1.0 事务B执行update tb_elc_forecast set capital = capital - 1.0, outbound = outbound + 1.0 where id = 1164727

and capital >= 1.0

T2时刻事务A执行update tb_elc_forecast set capital = capital - 1.0, outbound = outbound + 1.0 where id = 1164727and capital >= 1.0 事务B执行update tb_elc_forecast set capital = capital - 1.0, outbound = outbound + 1.0 where id = 1131766

and capital >= 1.0。每个事务通过执行两个update操作,这样形成了死锁条件。

那么事情果真如此吗?通过模拟测试,结果是肯定的。

结合死锁图示,这里的临界资源1是id=1164727的记录锁,临界资源是id=1131766的记录锁。update操作会占用各自id的记录锁资源。

通过一番查找,比较容易找到程序里对应的事务代码(使用了肇事SQL的业务逻辑代码),贴出部分如下:

for(ElcForecastTran entity : insertList) {
ElcForecast elcForecast= newElcForecast();

String period= new SimpleDateFormat("yyyy-MM").format(request.getOrderTime());

elcForecast.setCustomerid(entity.getCustomerid());

elcForecast.setSku(entity.getSku());

elcForecast.setPeriod(period);

elcForecast.setTp(entity.getTp());

elcForecast.setChannel(entity.getChannel());

elcForecast.setDepth(2); //子代理

elcForecast.setIsActive(1); //已发布

Integer id =elcForecastMapper.selectId(elcForecast);if(id == null){
isCapitalForecastFail= true;

builder.append(entity.getSku()).append(",");

logger.error("updateCapital fail,update forecast:{},request:{}",elcForecast,request);continue;

}

elcForecast.setId(id);

elcForecast.setCapital(entity.getCapital());//占用额度

cnt =elcForecastMapper.updateCapitalOutbound(elcForecast);

}

通过上下业务环境得知,此处事务方法,会存在同时被多线程调用问题,且代码:elcForecastMapper.updateCapitalOutbound(elcForecast);置于循环语句中,更新的对象elcForecast再不同线程中可能会存在重复的对象,故形成上述2死锁猜想条件。

那么怎么解决呢?可能有多种方法,一种是将事务拆分成小事务,不要把整个循环置于一个事务中。二是对此处事务加分布式锁,保证一次只允许一个线程调用即可。具体方案视业务情况来定。

接下来我通过一个具体的死锁实验来讲述以上死锁发生的原理

首先打开两个MySQL客户端,并执行set SESSION autocommit=0;关闭事务自动提交功能

准备两条测试SQL:update tb_elc_forecast set capital = capital - 1.0 where id=5133;和update tb_elc_forecast set capital = capital - 1.0 where id=5137;

分别在两个客户端执行事务启动语句:START TRANSACTION;

客户端A执行:update tb_elc_forecast set capital = capital - 1.0 where id=5133;

客户端B执行:update tb_elc_forecast set capital = capital - 1.0 where id=5137;

客户端A执行:update tb_elc_forecast set capital = capital - 1.0 where id=5137;

客户端B执行:update tb_elc_forecast set capital = capital - 1.0 where id=5133;

此时你该看到客户端B死锁发生了,并牺牲了自己,让客户端A事务存活。

客户端A执行:commit;

客户端B执行:commit;

实验如图:

分别为客户端A和B截图

客户端执行:SHOW ENGINE INNODB STATUS;

可以看到MySQL最近的死锁信息记录如下:

=====================================

2019-09-25 19:32:10 0x3a88 INNODB MONITOR OUTPUT

=====================================

Per second averages calculated from the last 10 seconds

-----------------

BACKGROUND THREAD

-----------------

srv_master_thread loops: 44 srv_active, 0 srv_shutdown, 4905 srv_idle

srv_master_thread log flush and writes: 4949

----------

SEMAPHORES

----------

OS WAIT ARRAY INFO: reservation count 40

OS WAIT ARRAY INFO: signal count 41

RW-shared spins 0, rounds 78, OS waits 35

RW-excl spins 0, rounds 39, OS waits 1

RW-sx spins 2, rounds 60, OS waits 2

Spin rounds per wait: 78.00 RW-shared, 39.00 RW-excl, 30.00 RW-sx

------------------------

LATEST DETECTED DEADLOCK

------------------------

2019-09-25 19:31:55 0x52c4

*** (1) TRANSACTION:

TRANSACTION 304429, ACTIVE 37 sec starting index read

mysql tables in use 1, locked 1

LOCK WAIT 3 lock struct(s), heap size 1136, 2 row lock(s), undo log entries 1

MySQL thread id 13, OS thread handle 27608, query id 12406 localhost ::1 root updating

update tb_elc_forecast set capital = capital - 1.0 where id=5137

*** (1) WAITING FOR THIS LOCK TO BE GRANTED:

RECORD LOCKS space id 467 page no 6 n bits 120 index PRIMARY of table `test`.`tb_elc_forecast` trx id 304429 lock_mode X locks rec but not gap waiting

Record lock, heap no 6 PHYSICAL RECORD: n_fields 44; compact format; info bits 0

0: len 4; hex 80001411; asc ;;

1: len 6; hex 00000004a52e; asc .;;

2: len 7; hex 22000002f72374; asc " #t;;

3: len 30; hex 39643231346264652d656532312d343034612d393862632d396261356232; asc 9d214bde-ee21-404a-98bc-9ba5b2; (total 36 bytes);

4: len 10; hex 304d4d30303130303030; asc 0MM0010000;;

5: len 7; hex 59534c44303031; asc YSLD001;;

6: len 4; hex 0000a041; asc A;;

7: len 4; hex 000080bf; asc ;;

8: len 4; hex 000040c0; asc @ ;;

9: len 4; hex 00000000; asc ;;

10: len 4; hex 00000000; asc ;;

11: len 7; hex 323031392d3033; asc 2019-03;;

12: len 9; hex 4252414e4453495445; asc BRANDSITE;;

13: len 14; hex 776d735f656c635f62616f7a756e; asc wms_elc_baozun;;

14: len 4; hex 80000002; asc ;;

15: len 4; hex 80000000; asc ;;

16: len 4; hex 80000000; asc ;;

17: len 5; hex 99a282e9bb; asc ;;

18: SQL NULL;

19: len 6; hex 363739303539; asc 679059;;

20: SQL NULL;

21: len 4; hex 8000140d; asc ;;

22: SQL NULL;

23: SQL NULL;

24: SQL NULL;

25: SQL NULL;

26: SQL NULL;

27: len 2; hex 3031; asc 01;;

28: len 12; hex 4252414e44534954455f3031; asc BRANDSITE_01;;

29: SQL NULL;

30: len 30; hex 4c4f43204332204242205741544552e280bbe580a9e7a2a7e6b481e99da2; asc LOC C2 BB WATER ; (total 45 bytes);

31: len 9; hex 4252414e4453495445; asc BRANDSITE;;

32: len 1; hex 59; asc Y;;

33: len 1; hex 59; asc Y;;

34: len 4; hex 80000000; asc ;;

35: SQL NULL;

36: len 4; hex 00000000; asc ;;

37: len 4; hex 00000000; asc ;;

38: len 4; hex 80000000; asc ;;

39: len 4; hex 80000000; asc ;;

40: SQL NULL;

41: SQL NULL;

42: len 4; hex 00000000; asc ;;

43: len 4; hex 00000000; asc ;;

*** (2) TRANSACTION:

TRANSACTION 304430, ACTIVE 30 sec starting index read, thread declared inside InnoDB 5000

mysql tables in use 1, locked 1

3 lock struct(s), heap size 1136, 2 row lock(s), undo log entries 1

MySQL thread id 14, OS thread handle 21188, query id 12407 localhost ::1 root updating

update tb_elc_forecast set capital = capital - 1.0 where id=5133

*** (2) HOLDS THE LOCK(S):

RECORD LOCKS space id 467 page no 6 n bits 120 index PRIMARY of table `test`.`tb_elc_forecast` trx id 304430 lock_mode X locks rec but not gap

Record lock, heap no 6 PHYSICAL RECORD: n_fields 44; compact format; info bits 0

0: len 4; hex 80001411; asc ;;

1: len 6; hex 00000004a52e; asc .;;

2: len 7; hex 22000002f72374; asc " #t;;

3: len 30; hex 39643231346264652d656532312d343034612d393862632d396261356232; asc 9d214bde-ee21-404a-98bc-9ba5b2; (total 36 bytes);

4: len 10; hex 304d4d30303130303030; asc 0MM0010000;;

5: len 7; hex 59534c44303031; asc YSLD001;;

6: len 4; hex 0000a041; asc A;;

7: len 4; hex 000080bf; asc ;;

8: len 4; hex 000040c0; asc @ ;;

9: len 4; hex 00000000; asc ;;

10: len 4; hex 00000000; asc ;;

11: len 7; hex 323031392d3033; asc 2019-03;;

12: len 9; hex 4252414e4453495445; asc BRANDSITE;;

13: len 14; hex 776d735f656c635f62616f7a756e; asc wms_elc_baozun;;

14: len 4; hex 80000002; asc ;;

15: len 4; hex 80000000; asc ;;

16: len 4; hex 80000000; asc ;;

17: len 5; hex 99a282e9bb; asc ;;

18: SQL NULL;

19: len 6; hex 363739303539; asc 679059;;

20: SQL NULL;

21: len 4; hex 8000140d; asc ;;

22: SQL NULL;

23: SQL NULL;

24: SQL NULL;

25: SQL NULL;

26: SQL NULL;

27: len 2; hex 3031; asc 01;;

28: len 12; hex 4252414e44534954455f3031; asc BRANDSITE_01;;

29: SQL NULL;

30: len 30; hex 4c4f43204332204242205741544552e280bbe580a9e7a2a7e6b481e99da2; asc LOC C2 BB WATER ; (total 45 bytes);

31: len 9; hex 4252414e4453495445; asc BRANDSITE;;

32: len 1; hex 59; asc Y;;

33: len 1; hex 59; asc Y;;

34: len 4; hex 80000000; asc ;;

35: SQL NULL;

36: len 4; hex 00000000; asc ;;

37: len 4; hex 00000000; asc ;;

38: len 4; hex 80000000; asc ;;

39: len 4; hex 80000000; asc ;;

40: SQL NULL;

41: SQL NULL;

42: len 4; hex 00000000; asc ;;

43: len 4; hex 00000000; asc ;;

*** (2) WAITING FOR THIS LOCK TO BE GRANTED:

RECORD LOCKS space id 467 page no 6 n bits 120 index PRIMARY of table `test`.`tb_elc_forecast` trx id 304430 lock_mode X locks rec but not gap waiting

Record lock, heap no 54 PHYSICAL RECORD: n_fields 44; compact format; info bits 0

0: len 4; hex 8000140d; asc ;;

1: len 6; hex 00000004a52d; asc -;;

2: len 7; hex 21000002d522ea; asc ! " ;;

3: len 30; hex 34326237346466332d383133372d346639372d393435382d613939613266; asc 42b74df3-8137-4f97-9458-a99a2f; (total 36 bytes);

4: len 10; hex 304d4d30303130303030; asc 0MM0010000;;

5: len 7; hex 59534c44303031; asc YSLD001;;

6: len 4; hex 00004842; asc HB;;

7: len 4; hex 000080bf; asc ;;

8: len 4; hex 000040c0; asc @ ;;

9: SQL NULL;

10: len 4; hex 00004842; asc HB;;

11: len 7; hex 323031392d3033; asc 2019-03;;

12: SQL NULL;

13: SQL NULL;

14: len 4; hex 80000001; asc ;;

15: len 4; hex 80000002; asc ;;

16: len 4; hex 80000001; asc ;;

17: len 5; hex 99a282e9bb; asc ;;

18: len 5; hex 99a288b39e; asc ;;

19: len 6; hex 363739303539; asc 679059;;

20: SQL NULL;

21: SQL NULL;

22: SQL NULL;

23: SQL NULL;

24: SQL NULL;

25: SQL NULL;

26: SQL NULL;

27: len 2; hex 3031; asc 01;;

28: len 12; hex 4252414e44534954455f3031; asc BRANDSITE_01;;

29: SQL NULL;

30: len 30; hex 4c4f43204332204242205741544552e280bbe580a9e7a2a7e6b481e99da2; asc LOC C2 BB WATER ; (total 45 bytes);

31: len 9; hex 4252414e4453495445; asc BRANDSITE;;

32: len 1; hex 59; asc Y;;

33: len 1; hex 59; asc Y;;

34: len 4; hex 80000000; asc ;;

35: SQL NULL;

36: len 4; hex 00006041; asc `A;;

37: len 4; hex 00000000; asc ;;

38: len 4; hex 80000002; asc ;;

39: len 4; hex 80000001; asc ;;

40: len 21; hex 4f4d53e5ba93e5ad98e69fa5e8afa2e68890e58a9f; asc OMS ;;

41: len 30; hex 61303730393438612d633531642d346331362d616433392d393434393038; asc a070948a-c51d-4c16-ad39-944908; (total 36 bytes);

42: len 4; hex 00000000; asc ;;

43: len 4; hex 00000000; asc ;;

*** WE ROLL BACK TRANSACTION (2)

------------

TRANSACTIONS

------------

Trx id counter 304432

Purge done for trx's n:o < 304432 undo n:o < 0 state: running but idle

History list length 13

LIST OF TRANSACTIONS FOR EACH SESSION:

---TRANSACTION 283332952971320, not started

0 lock struct(s), heap size 1136, 0 row lock(s)

---TRANSACTION 283332952973936, not started

0 lock struct(s), heap size 1136, 0 row lock(s)

---TRANSACTION 283332952973064, not started

0 lock struct(s), heap size 1136, 0 row lock(s)

---TRANSACTION 283332952972192, not started

0 lock struct(s), heap size 1136, 0 row lock(s)

---TRANSACTION 283332952968704, not started

0 lock struct(s), heap size 1136, 0 row lock(s)

---TRANSACTION 283332952967832, not started

0 lock struct(s), heap size 1136, 0 row lock(s)

---TRANSACTION 283332952966960, not started

0 lock struct(s), heap size 1136, 0 row lock(s)

---TRANSACTION 304429, ACTIVE 52 sec

3 lock struct(s), heap size 1136, 2 row lock(s), undo log entries 2

MySQL thread id 13, OS thread handle 27608, query id 12406 localhost ::1 root

---TRANSACTION 304408, ACTIVE 4442 sec

2 lock struct(s), heap size 1136, 1 row lock(s)

MySQL thread id 9, OS thread handle 14984, query id 12411 localhost 127.0.0.1 root starting

show ENGINE INNODB STATUS

---TRANSACTION 304407, ACTIVE 4450 sec

2 lock struct(s), heap size 1136, 1 row lock(s)

MySQL thread id 8, OS thread handle 25856, query id 12278 localhost 127.0.0.1 root

--------

FILE I/O

--------

I/O thread 0 state: wait Windows aio (insert buffer thread)

I/O thread 1 state: wait Windows aio (log thread)

I/O thread 2 state: wait Windows aio (read thread)

I/O thread 3 state: wait Windows aio (read thread)

I/O thread 4 state: wait Windows aio (read thread)

I/O thread 5 state: wait Windows aio (read thread)

I/O thread 6 state: wait Windows aio (write thread)

I/O thread 7 state: wait Windows aio (write thread)

I/O thread 8 state: wait Windows aio (write thread)

I/O thread 9 state: wait Windows aio (write thread)

Pending normal aio reads: [0, 0, 0, 0] , aio writes: [0, 0, 0, 0] ,

ibuf aio reads:, log i/o's:, sync i/o's:

Pending flushes (fsync) log: 0; buffer pool: 0

609 OS file reads, 1233 OS file writes, 226 OS fsyncs

0.00 reads/s, 0 avg bytes/read, 0.00 writes/s, 0.00 fsyncs/s

-------------------------------------

INSERT BUFFER AND ADAPTIVE HASH INDEX

-------------------------------------

Ibuf: size 1, free list len 207, seg size 209, 0 merges

merged operations:

insert 0, delete mark 0, delete 0

discarded operations:

insert 0, delete mark 0, delete 0

Hash table size 2267, node heap has 0 buffer(s)

Hash table size 2267, node heap has 1 buffer(s)

Hash table size 2267, node heap has 0 buffer(s)

Hash table size 2267, node heap has 0 buffer(s)

Hash table size 2267, node heap has 0 buffer(s)

Hash table size 2267, node heap has 0 buffer(s)

Hash table size 2267, node heap has 0 buffer(s)

Hash table size 2267, node heap has 0 buffer(s)

0.00 hash searches/s, 0.00 non-hash searches/s

---

LOG

---

Log sequence number 412469041

Log flushed up to 412469041

Pages flushed up to 412469041

Last checkpoint at 412469032

0 pending log flushes, 0 pending chkp writes

118 log i/o's done, 0.00 log i/o's/second

----------------------

BUFFER POOL AND MEMORY

----------------------

Total large memory allocated 8585216

Dictionary memory allocated 128725

Buffer pool size 512

Free buffers 255

Database pages 256

Old database pages 0

Modified db pages 0

Pending reads 0

Pending writes: LRU 0, flush list 0, single page 0

Pages made young 0, not young 0

0.00 youngs/s, 0.00 non-youngs/s

Pages read 580, created 672, written 1023

0.00 reads/s, 0.00 creates/s, 0.00 writes/s

No buffer pool page gets since the last printout

Pages read ahead 0.00/s, evicted without access 0.00/s, Random read ahead 0.00/s

LRU len: 256, unzip_LRU len: 0

I/O sum[10]:cur[0], unzip sum[0]:cur[0]

--------------

ROW OPERATIONS

--------------

0 queries inside InnoDB, 0 queries in queue

0 read views open inside InnoDB

Process ID=27356, Main thread ID=21352, state: sleeping

Number of rows inserted 13258, updated 11, deleted 0, read 108651

0.00 inserts/s, 0.00 updates/s, 0.00 deletes/s, 0.00 reads/s

----------------------------

END OF INNODB MONITOR OUTPUT

============================

关于死锁测试,最好使用MySQL自带的Console客户端实验,不要使用第三方可视化工具,效果不太好。

浅析MySQL死锁检测 这里梳理了下死锁检测的流程,由于水平有限,文章可能存在不正确地方,望指正。 阅读详情

相关推荐

一个mysql死锁问题的分析

mysql死锁案例分析

yonggeit的博客 4139

mysql 制造一个死锁_MySql一个生产死锁案例分析

接到上级一个生产环境MySQL死锁日志信息文件,需要找出原因并解决问题。我将死锁日志部分贴出如下:在mysql中使用命令:SHOW ENGINE INNODB STATUS;总能获取到最近一些问题信息,通过搜索deadlock 关键字即可找到死锁的相关日志信息。2019-09-25 13:28:25 7fc0301ca700InnoDB: transactions deadlock detecte...

weixin_35748716的博客 960

ACM论文LaTeX模板解析(三)| 文章顶部信息(Top matter))Part 1

文章顶部信息(Top matter))Part 1,文章类型、作者信息等

FreshManInC的博客 4853

深入浅出InnoDB Locking

深入浅出InnoDB Locking

CERTAINTY的博客 671

手把手教你用Python实现双三次插值(附OpenCV对比测试)

本文深入解析了双三次插值算法的数学原理,并提供了从零开始的Python实现教程。通过与OpenCV官方实现的对比测试,详细评估了不同插值算法(包括最邻近差值、双线性插值)在图像质量与计算性能上的差异,帮助开发者掌握高质量图像缩放的核心技术。

weixin_29310605的博客 293

华为HCIP大数据备考实战:从题库精析到834分通关策略

本文详细介绍了华为HCIP大数据认证考试的备考策略,包括题库精析、重点章节突破和考场实战经验。作者以834分的高分通过考试,分享了官方教材的三遍阅读法、自建题库技巧以及各章节核心知识点,帮助考生高效备考并顺利通关。

weixin_29169899的博客 149

解决一次mysql死锁问题

解决一次mysql死锁问题 背景 多线程开启事务处理。每个事务有多个update操作和一个insert操作(都在同一张表)。 DDL(删除了一些不必要的细节) 默认隔离级别:Repeatable Read CREATE TABLE `list_rate` ( `id` bigint(20) NOT NULL AUTO_INCREMENT, `hotel_id` bigint(20) NOT NULL, `rate_date` date NOT NULL, `room_type_i

hhj13978064496的博客 1168

KiCad 7.0 + 嘉立创打样:从原理图到实物,打造你的双LLCC68 LoRa串口透传板

本文详细介绍了使用KiCad 7.0设计双LLCC68 LoRa串口透传板的完整流程,从原理图设计到嘉立创打样。重点解析了AVR+LLCC68组合的优势、双模块布局的电磁兼容设计、SPI接口配置及射频走线技巧,并提供了实测数据和常见问题解决方案,帮助开发者高效实现物联网设备的低功耗远距离通信。

weixin_28693447的博客 259

批量更新出现死锁问题

通常使用insert、update、delete等操作的时候,数据库会进行锁表操作。需要在条件字段添加上索引条件,使表锁转换成行级锁,减少对数据的锁定。),行锁会先对非主键索引进行锁定在进行主键索引锁定。所以当更新语句操作到非主键索引时,不仅会锁行记录,还会锁住非主键索引。从而占用资源导致死锁。update语句进行不要对非主键索引进行操作,避免更多资源的锁定。Mysql出现死锁主要是有两种情况。- 第二种是,数据库出现行级锁(

weixin_49363689的博客 5548

安卓逆向实战:利用Frida-RPC自动化获取大麦演唱会数据

本文详细介绍了如何利用Frida-RPC技术实现安卓逆向自动化,以获取大麦演唱会数据。通过实战演示,从环境搭建、使用Frida动态分析定位核心签名算法,到封装为可复用的Python脚本,完整解析了自动化数据获取的技术路径与工程化思考。

cheese的博客 974

面试官连夜整理:103道AI Agent面试题,答对一半直接加薪50%

维度AutoGPTLangGraphAutoGen控制流LLM 驱动的隐式循环代码层定义的显式状态图对话驱动的自动流转状态存储Prompt 上下文中(易丢失)结构化 State 对象(可持久化)对话历史(自动累积)分支能力依赖 LLM 的文本输出(不稳定)条件边 + 节点路由(确定性)多 Agent 对话自然分支(涌现式)回溯/回滚无原生支持,只能重新开始原生 Checkpoint 支持时间旅行无全局回滚,单 Agent 可重启人机协同仅人工在关键点介入(需要自定义)原生支持。

weixin_35774598的博客 620

innodb锁详解

如果是索引唯一扫描或主键唯一扫描,innodb只会上行锁锁住一行数据。如果是索引范围扫描或主键范围扫描,innodb会上临键锁。唯一索引同样会有索引范围扫描,仅在等值条件下扫描唯一索引(或主键)才会触发唯一扫描。 临键锁会锁住“小于范围的最大存在值和大于范围的最小存在值”,如果没有实际存在值,innodb会给临键锁“超大值”或“超小值”去锁一个大范围。所以在某些情况下,一个update可以锁住整张表。

liuzhilong的博客 1719

NVIDIA Isaac Sim 入门教程(一)

文档分为以下几个部分: 简介、安装指南、API 文档、教程、手册和参考资料。简介部分是对 Omniverse Isaac Sim 的基本概述,以及它如何融入 NVIDIA Omniverse™ 生态系统。它还概述了 Omniverse Isaac Sim 的架构、工作流程和文档布局。

机器人控制与仿真应用 1万+

彻底了解MySQL中的各种锁,不再迷茫,有详细的案例,死锁,锁等待,乐观锁,排他锁等

MySQL 中的锁机制包括行级锁、表级锁、共享锁、排它锁、意向锁等。死锁是一种资源争夺的极端情况,通常会导致事务回滚,影响数据一致性。死锁的解决方案主要依赖于减少锁争用、合理设计事务流程。锁等待是一种事务在等待资源的状态,可能会影响性能,特别是在高并发场景中。通过优化索引、调整锁粒度和合理设计查询,可以减少锁等待带来的影响。行级锁提供较高的并发性,但也容易导致锁等待和死锁。表级锁性能较低,但适用于需要修改整个表的数据。共享锁允许并发读取,但限制了修改操作。排它锁。

2302_81910295的博客 1072

jre9下载 jdk9

(Java SE Runtime Environment 9.0) 9.0u175 官方最新版 【x86|x64】

Devexpress16.2.6破解工具

Devexpress16.2.6破解工具Devexpress16.2.6破解工具Devexpress16.2.6破解工具Devexpress16.2.6破解工具

MySQL死锁案例分析及避免办法

死锁就是两个以上线程互相竞争资源导致相互等待的现象发生死锁有四个条件:互斥、请求与保持条件、不可抢占、循环等待。

假人一个的博客 1870

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

MySql 死锁

MySql 死锁一、什么是死锁InnoDB存储引擎定义了四种类型的行锁隔离等级对加锁的影响当前数据对加锁的影响二、为什么会形成死锁两阶段锁协议产生死锁的四个必要条件三、MySQL 如何处理死锁?杀死进程MySQL表间隙锁排他锁共享锁分析行锁定行锁优化四、如何避免发生死锁1.对索引加锁顺序的不一致很可能会导致死锁;2.Gap 锁往往是程序中导致死锁的真凶;3.为表添加合理的索引,如果不走索引将会为表的每一行记录加锁,死锁的概率就会大大增大;4.我们知道 MyISAM 只支持表锁,它采用一次封锁技术来保证事务之

wgchen 5106

NTscan扫描工具

ntscan是一个扫描器,可以扫描没有密码和弱密码的共享,先到配置文件中填写猜测的用户名和密码,扫描过程中右侧出现的是扫描日志。

在 MySQL 中,如何处理和分析死锁

死锁是指两个或多个事务在互相等待对方释放资源,从而导致所有事务都无法继续执行的情况。在 MySQL 中,死锁通常发生在多个事务同时对多个资源进行操作时,由于操作顺序不当或者资源竞争导致的。

我爱娃哈哈的专栏 1588

一次生产上的mysql死锁原因排查

最近在生产上遇到了一个mysql死锁的问题,花了一整天才排查出来,现在本地造出同种场景的死锁。 1、在CMD命令窗口敲入命令 mysql -hlocalhost -uroot -p 2、进入数据库test use test 3、建表语句: CREATETABLE`user`( `id`bigint(64)NOTNULLAUTO_INCREMENT, `usern...

brushli的专栏 1587

MySQL死锁了怎么处理?

死锁指两个(或多个)事务在执行过程中,因为持有资源相互等待,且彼此都不主动释放锁导致事务永远相互等待的局面。在InnoDB中,一旦检测到死锁,InnoDB会自动选择牺牲一个事务进行回滚,让其他事务继续执行。✅MySQL遇到死锁,会自动检测并回滚开销最小的事务,我们需要通过标准化访问顺序、小事务、加索引等手段减少死锁,同时要做好死锁后的自动恢复机制(重试+报警)。MySQL死锁排查与分析高级技巧✅死锁不是异常现象,是系统自然演化的一部分。✅。

weixin_46072507的博客 3303

MySQL并发死锁案例分析一

目录 1、前言 2、数据库准备 3、案例分析 一、前言 死锁问题是并发系统中绕不开的一个话题,同样在数据库MySQL存储引擎Innodb中并发情况下死锁问题也屡见不鲜。对于死锁定义、死锁产生的条件、各种锁之间的兼容关系、死锁检测相关内容本篇文章不做深入介绍,本篇文章只有一个关注点——如何分析死锁。 二、数据库准备 数据库结构: CREATE TABLE `student` ( ...

wenyixicodedog的博客 697

MySQL 死锁

MySQL 中的事务是一组数据库操作的逻辑单元,这些操作要么全部成功执行,要么全部失败回滚,保证了数据的一致性和完整性。例如,在一个银行转账系统中,从账户 A 转出一笔钱到账户 B,这个过程涉及到两个操作:一是账户 A 的余额减少,二是账户 B 的余额增加,这两个操作就应该放在一个事务里,只有当两个操作都成功完成时,整个转账事务才算成功,要是其中一个操作出现问题,比如账户 A 余额不足无法转出,那么整个事务就要回滚,账户 B 的余额也不会增加,这样就能保证数据始终处于正确的状态。

果酱 の 博客 1917

mysql 并发_MySQL并发死锁案例分析一

目录1、前言2、数据库准备3、案例分析一、前言死锁问题是并发系统中绕不开的一个话题,同样在数据库MySQL存储引擎Innodb中并发情况下死锁问题也屡见不鲜。对于死锁定义、死锁产生的条件、各种锁之间的兼容关系、死锁检测相关内容本篇文章不做深入介绍,理解本文的前提是假设对这些东西已经有了一定的了解,本篇文章只有一个关注点——如何分析死锁。二、数据库准备数据库结构:CREATE TABLE ...

weixin_39804620的博客 146

mysql死锁常见的案例分析

1.无序更新引发的死锁 起因:在最近的项目中遇到一个死锁的场景,其它系统会推送一些单据(主表和从表结构)到我的系统中更新数据,而单据在我的系统中也提供给业务人员做修改操作; 就这么一个场景,我们创建一张表来模拟出问题所在; 创建一张测试表 CREATE TABLE lock_test( id INT PRIMARY KEY AUTO_INCREMENT, codeNo INT, number INT, UNIQUE code_index(codeNo) ) ENGINE=InnoDB id

shixiaoling123的博客 622
上一篇: MySQL中for update的作用和用法
下一篇: 重新学习Mysql数据库4:Mysql索引实现原理和相关数据结构算法
wrr-cat
博客等级 码龄9年 128粉丝 302原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值