1. 14.5.5.1 An InnoDB Deadlock Example 一个InnoDB 死锁实例
  2.  
  3. 下面的例子演示了一个错误可以发生当一个lock 请求会导致一个死锁,例子设计2个客户端,AB:
  4.  
  5. Jekins:/root# mysql -uroot -p1234567 -e"SHOW ENGINE INNODB STATUS\G;" | grep -i dead
  6. Warning: Using a password on the command line interface can be insecure.
  7.  
  8. 首先, client A 创建一个表包含一个记录, 然后开始一个事务,在事务中,通过selecting在共享模式得到一个S
  9.  
  10. mysql> CREATE TABLE t (i INT) ENGINE = InnoDB;
  11. Query OK, 0 rows affected (1.07 sec)
  12.  
  13. mysql> INSERT INTO t (i) VALUES(1);
  14. Query OK, 1 row affected (0.09 sec)
  15.  
  16. mysql> START TRANSACTION;
  17. Query OK, 0 rows affected (0.00 sec)
  18.  
  19. mysql> SELECT * FROM t WHERE i = 1 LOCK IN SHARE MODE;
  20. +------+
  21. | i |
  22. +------+
  23. | 1 |
  24. +------+
  25.  
  26. 接着,Client B 开始一个事务和尝试删除记录
  27.  
  28. mysql> START TRANSACTION;
  29. Query OK, 0 rows affected (0.00 sec)
  30.  
  31. mysql> DELETE FROM t WHERE i = 1;
  32.  
  33. 删除操作需要一个X锁,lock 不能被立即授权 因为它不兼容S 客户端A持有的,
  34.  
  35. 最后,Client A 尝试删除表的记录
  36.  
  37. mysql> DELETE FROM t WHERE i = 1;
  38. ERROR 1213 (40001): Deadlock found when trying to get lock;
  39. try restarting transaction
  40.  
  41. Deadlock 发生 因为client A 需要一个X锁来删除记录。
  42.  
  43. 然而,lock 请求不能被立即授予因为Client B有一个请求X 在等待客户端A 来释放他的S锁。
  44.  
  45. S锁被client A持有的也不能升级为X 。这样,InnoDB 产生一个错误
  46.  
  47. ------------------------
  48. LATEST DETECTED DEADLOCK
  49. ------------------------
  50. 2016-10-31 10:06:09 7f0341d30700
  51. *** (1) TRANSACTION:
  52. TRANSACTION 15945, ACTIVE 5 sec starting index read
  53. mysql tables in use 1, locked 1
  54. LOCK WAIT 2 lock struct(s), heap size 360, 1 row lock(s)
  55. MySQL thread id 5, OS thread handle 0x7f0341ae9700, query id 368 localhost root updating
  56. DELETE FROM t WHERE i = 1
  57. *** (1) WAITING FOR THIS LOCK TO BE GRANTED:
  58. RECORD LOCKS space id 583 page no 3 n bits 72 index `GEN_CLUST_INDEX` of table `zjzc`.`t` trx id 15945 lock_mode X waiting
  59. Record lock, heap no 2 PHYSICAL RECORD: n_fields 4; compact format; info bits 0
  60. 0: len 6; hex 000000005c00; asc \ ;;
  61. 1: len 6; hex 000000003e47; asc >G;;
  62. 2: len 7; hex c7000001be0110; asc ;;
  63. 3: len 4; hex 80000001; asc ;;
  64.  
  65. *** (2) TRANSACTION:
  66. TRANSACTION 15944, ACTIVE 24 sec starting index read
  67. mysql tables in use 1, locked 1
  68. 4 lock struct(s), heap size 1184, 3 row lock(s)
  69. MySQL thread id 4, OS thread handle 0x7f0341d30700, query id 369 localhost root updating
  70. DELETE FROM t WHERE i = 1
  71. *** (2) HOLDS THE LOCK(S):
  72. RECORD LOCKS space id 583 page no 3 n bits 72 index `GEN_CLUST_INDEX` of table `zjzc`.`t` trx id 15944 lock mode S
  73. Record lock, heap no 1 PHYSICAL RECORD: n_fields 1; compact format; info bits 0
  74. 0: len 8; hex 73757072656d756d; asc supremum;;
  75.  
  76. Record lock, heap no 2 PHYSICAL RECORD: n_fields 4; compact format; info bits 0
  77. 0: len 6; hex 000000005c00; asc \ ;;
  78. 1: len 6; hex 000000003e47; asc >G;;
  79. 2: len 7; hex c7000001be0110; asc ;;
  80. 3: len 4; hex 80000001; asc ;;
  81.  
  82. *** (2) WAITING FOR THIS LOCK TO BE GRANTED:
  83. RECORD LOCKS space id 583 page no 3 n bits 72 index `GEN_CLUST_INDEX` of table `zjzc`.`t` trx id 15944 lock_mode X waiting
  84. Record lock, heap no 2 PHYSICAL RECORD: n_fields 4; compact format; info bits 0
  85. 0: len 6; hex 000000005c00; asc \ ;;
  86. 1: len 6; hex 000000003e47; asc >G;;
  87. 2: len 7; hex c7000001be0110; asc ;;
  88. 3: len 4; hex 80000001; asc ;;
  89.  
  90. *** WE ROLL BACK TRANSACTION (1)

14.5.5.1 An InnoDB Deadlock Example 一个InnoDB 死锁实例的更多相关文章

  1. 14.3.5.1 An InnoDB Deadlock Example

    14.3.5 Deadlocks in InnoDB 14.3.5.1 An InnoDB Deadlock Example 14.3.5.2 Deadlock Detection and Rollb ...

  2. 14.3.5.2 Deadlock Detection and Rollback 死锁检测和回滚:

    14.3.5.2 Deadlock Detection and Rollback 死锁检测和回滚: InnoDB 自动检查四艘,回滚一个事务或者事务来打破死锁. InnoDB 试图选择小的事务来回滚, ...

  3. 14.8.2 Role of the .frm File for InnoDB Tables InnoDB 表得到 .frm文件的作用

    14.8.2 Role of the .frm File for InnoDB Tables InnoDB 表得到 .frm文件的作用 Vsftp:/data01/mysql/zjzc# ls -lt ...

  4. 14.7.2 Changing the Number or Size of InnoDB Redo Log Files 改变InnoDB Redo Log Files的数量和大小

    14.7.2 Changing the Number or Size of InnoDB Redo Log Files 改变InnoDB Redo Log Files的数量和大小 改变 InnoDB ...

  5. 14.6.7 Configuring the Number of Background InnoDB IO Threads 配置InnoDB IO Threads的数量

    14.6.7 Configuring the Number of Background InnoDB IO Threads 配置InnoDB IO Threads的数量 InnoDB 使用后台线程来服 ...

  6. 14.6.5 Configuring InnoDB Change Buffering 配置InnoDB Change Buffering

    14.6.5 Configuring InnoDB Change Buffering 配置InnoDB Change Buffering 当插入,更新,和删除操作在表上执行, 索引列的值(特别是 se ...

  7. 14.19 InnoDB and MySQL Replication InnoDB 和MySQL 复制:

    14.19 InnoDB and MySQL Replication InnoDB 和MySQL 复制: MySQL 复制工作对于InnoDB 表和对于MyISAM表. 它是可能使用复制的方式 存储引 ...

  8. 14.5.2 Changing the Number or Size of InnoDB Redo Log Files 改变InnoDB Redo Log Files的数量

    14.5.2 Changing the Number or Size of InnoDB Redo Log Files 改变InnoDB Redo Log Files的数量 改变InnoDB redo ...

  9. 14.4.5 Configuring InnoDB Change Buffering 配置InnoDB Change Buffering

    14.4.5 Configuring InnoDB Change Buffering 配置InnoDB Change Buffering 当INSERT,UPDATE,和删除操作在表上操作, 索引列的 ...

随机推荐

  1. Java基础知识强化之集合框架笔记64:Map集合之ArrayList嵌套HashMap

    1. ArrayList集合嵌套HashMap集合并遍历.  需求:         假设ArrayList集合的元素是HashMap.有3个.         每一个HashMap集合的键和值都是字 ...

  2. [页面辅助] 最新的 PageValidate 类 (转载)

    代码 using System; using System.Data; using System.Configuration; using System.Web; using System.Text. ...

  3. ImageView的子类无法加载图片

    在图片预览时,偶现图片无法现实,在查看程序的时候发现Bitmap是实际存在的,但是在ImageView中缺绘制不出来,这个问题困然了我很久,查看代码也查不出原因,再加上是偶现的,查原因时费了不少时间. ...

  4. C# - linq查询现有的DataTable

    可以通过linq对现有的DataTable进行查询,并将结果拷贝至新的DataTable中例如: // Query the SalesOrderHeader table for orders plac ...

  5. 真机调试报错:Could not find Developer Disk Image 或 Could not locate device support files.

    废话不多说,原因是用的Xcode版本所支持的最高iOS系统低于真机iOS系统导致. 解决方案: 1.升级到最新的Xcode版本 2.不想升级Xcode,那就找已经把Xcode升级到最新版本的朋友,发给 ...

  6. UIimageView GIF动画

    1.代码如下 (注释都有) - (void)viewDidLoad { [super viewDidLoad]; UIImageView * bigImageView = [[UIImageView ...

  7. 判断ios是app第一次启动

    首次运行的应用程序加入一些help 或者 宣传动画 现在变的很重要了. 一个有用的例子是发送一个分析实例.这可能是一个很好的方法来确定有多少人下载实用应用程序.有人会说:“但是,嘿,苹果AppStor ...

  8. 7-1 DBA顾问培训内容@20141230

    1, 逻辑读还是物理读? 查询语句的实际执行计划. F5 预计执行计划. --如何产生实际执行计划 ??. --Session收集指令.   workload repository report fo ...

  9. Graphics类绘制图形

    1. 画直线 void drawLine(int startX,int startY,int endX,int endY); 四个参数分别为:起始点的x坐标和y坐标以及终点的x坐标和y坐标,该方法用于 ...

  10. zoj1276矩阵连乘dp

    很经典的入门dp /*******************************************************************************/ /* OS : 3 ...