mysql innodb 死锁_mysql innodb 死锁分析
mysql Ver 14.14 Distrib 5.7.16, for linux-glibc2.5 (x86_64) using EditLine wrapper #mysql版本 5.7.16
Connection id: 10042
Current database: china9129
Current user: root@localhost
SSL: Not in use
Current pager: stdout
Using outfile: ''
Using delimiter: ;
Server version: 5.7.16-log MySQL Community Server (GPL)
Protocol version: 10
Connection: Localhost via UNIX socket
Server characterset: utf8
Db characterset: utf8
Client characterset: utf8
Conn. characterset: utf8
UNIX socket: /data/mysql/mysql9129/sock/mysql9129.sock
Uptime: 4 days 6 hours 2 min 31 sec
Threads: 4 Questions: 31133 Slow queries: 0 Opens: 254 Flush tables: 3 Open tables: 58 Queries per second avg: 0.084
SESSION 1:
"root@localhost:mysql9129.sock [(none)]>set global TRANSACTION ISOLATION LEVEL REPEATABLE READ;
"root@localhost:mysql9129.sock [(none)]>select @@tx_isolation;
+-----------------+
| @@tx_isolation |
+-----------------+
| REPEATABLE-READ |
+-----------------+
1 row in set (0.00 sec)
"root@localhost:mysql9129.sock [china9129]>show create table t100;
+-------+----------------------------------------------------------------------------------------------------------+
| Table | Create Table |
+-------+----------------------------------------------------------------------------------------------------------+
| t100 | CREATE TABLE `t100` (
`id` int(11) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 |
+-------+----------------------------------------------------------------------------------------------------------+
1 row in set (0.00 sec)
"root@localhost:mysql9129.sock [china9129]>select * from t100;
+-----+
| id |
+-----+
| 1 |
| 2 |
| 3 |
| 4 |
| 5 |
| 111 |
+-----+
"root@localhost:mysql9129.sock [china9129]>begin;
Query OK, 0 rows affected (0.00 sec)
"root@localhost:mysql9129.sock [china9129]>select * from t100 where id=5 for update;
+----+
| id |
+----+
| 5 |
+----+
1 row in set (0.00 sec)
"root@localhost:mysql9129.sock [china9129]>delete from t100 where id =3;
Query OK, 1 row affected (3.62 sec)
==========================================================================================================
SESSION 2:
"root@localhost:mysql9129.sock [(none)]>begin;
Query OK, 0 rows affected (0.00 sec)
"root@localhost:mysql9129.sock [(none)]>use china9129;
Database changed
"root@localhost:mysql9129.sock [china9129]>select * from t100 where id=3 for update;
+----+
| id |
+----+
| 3 |
+----+
1 row in set (0.00 sec)
"root@localhost:mysql9129.sock [china9129]>delete from t100 where id =5;
ERROR 1213 (40001): Deadlock found when trying to get lock; try restarting transaction
#查看死锁信息
"root@localhost:mysql9129.sock [china9129]>show engine innodb status \G
*************************** 1. row ***************************
Type: InnoDB
Name:
Status:
=====================================
2016-12-20 21:57:45 0x7fa0bffff700 INNODB MONITOR OUTPUT
=====================================
Per second averages calculated from the last 24 seconds
-----------------
BACKGROUND THREAD
-----------------
srv_master_thread loops: 1133 srv_active, 0 srv_shutdown, 362529 srv_idle
srv_master_thread log flush and writes: 363662
----------
SEMAPHORES
----------
OS WAIT ARRAY INFO: reservation count 4540
OS WAIT ARRAY INFO: signal count 5766
RW-shared spins 0, rounds 4683, OS waits 474
RW-excl spins 0, rounds 134731, OS waits 1327
RW-sx spins 6332, rounds 138603, OS waits 2382
Spin rounds per wait: 4683.00 RW-shared, 134731.00 RW-excl, 21.89 RW-sx
------------------------
LATEST DETECTED DEADLOCK #监测出最近的死锁信息
------------------------
2016-12-20 21:56:29 0x7fa0bffff700
*** (1) TRANSACTION: #第一个事物
TRANSACTION 13899, ACTIVE 51 sec starting index read #事物id 13899,活跃了51秒
mysql tables in use 1, locked 1 #mysql有一个表在使用,一个表被锁住
LOCK WAIT 3 lock struct(s), heap size 1136, 2 row lock(s) #有3个锁链表,内存中堆的大小1136, 两行记录被锁定
MySQL thread id 10041, OS thread handle 140330009478912, query id 31128 localhost root updating
#mysql线程id 10041, query id 31128, localhost root用户执行update操作
delete from t100 where id =3 #执行了这个SQL语句的时候,发生了锁等待
*** (1) WAITING FOR THIS LOCK TO BE GRANTED: #等待这个锁被释放
RECORD LOCKS space id 74 page no 3 n bits 80 index PRIMARY of table `china9129`.`t100` trx id 13899 lock_mode X locks rec but not gap waiting
#类型:行锁,等待在t100的主键上 page num 3,加一个X锁(not gap waiting),锁住80 bits。
Record lock, heap no 5 PHYSICAL RECORD: n_fields 3; compact format; info bits 0
0: len 4; hex 80000003; asc ;;
1: len 6; hex 00000000363b; asc 6;;;
2: len 7; hex c7000001660110; asc f ;;
*** (2) TRANSACTION:#第二个事物
TRANSACTION 13900, ACTIVE 31 sec starting index read #事物id 13900,活跃了31秒
mysql tables in use 1, locked 1 #mysql有一个表在使用,一个表被锁住
3 lock struct(s), heap size 1136, 2 row lock(s) #有3个锁链表,内存中堆的大小1136, 两行记录被锁定
MySQL thread id 10042, OS thread handle 140328392718080, query id 31129 localhost root updating
#mysql线程id 10042, query id 31129, localhost root用户执行update操作
delete from t100 where id =5 #执行了这个SQL语句的时候,发生了锁等待
*** (2) HOLDS THE LOCK(S): #事物 13900 持有的锁
RECORD LOCKS space id 74 page no 3 n bits 80 index PRIMARY of table `china9129`.`t100` trx id 13900 lock_mode X locks rec but not gap
#类型:行锁,事物 id 13900,在t100的主键上 page num 3,加一个X锁(not gap 没有间隙锁),锁住80 bits
Record lock, heap no 5 PHYSICAL RECORD: n_fields 3; compact format; info bits 0
0: len 4; hex 80000003; asc ;;
1: len 6; hex 00000000363b; asc 6;;;
2: len 7; hex c7000001660110; asc f ;;
*** (2) WAITING FOR THIS LOCK TO BE GRANTED: #当事物2在执行delete from t100 where id =5的时候,发生锁等待
RECORD LOCKS space id 74 page no 3 n bits 80 index PRIMARY of table `china9129`.`t100` trx id 13900 lock_mode X locks rec but not gap waiting
#类型:行锁,等待在t100的主键上 page num 3,加一个X锁(not gap waiting 没有间隙锁),锁住80 bits。
Record lock, heap no 7 PHYSICAL RECORD: n_fields 3; compact format; info bits 0
0: len 4; hex 80000005; asc ;;
1: len 6; hex 00000000363d; asc 6=;;
2: len 7; hex c90000014c0110; asc L ;;
*** WE ROLL BACK TRANSACTION (2)
#事物2,TRANSACTION 13900被回滚了。报错信息:ERROR 1213 (40001): Deadlock found when trying to get lock; try restarting transaction
------------
TRANSACTIONS
------------
Trx id counter 13905
Purge done for trx's n:o
History list length 568
LIST OF TRANSACTIONS FOR EACH SESSION:
---TRANSACTION 421807334705888, not started
0 lock struct(s), heap size 1136, 0 row lock(s)
---TRANSACTION 13899, ACTIVE 127 sec
3 lock struct(s), heap size 1136, 2 row lock(s), undo log entries 1
MySQL thread id 10041, OS thread handle 140330009478912, query id 31128 localhost root cleaning up
-------
备注:
(1) 在MySQL中,行级锁并不是直接锁记录,而是锁索引。索引分为主键索引和非主键索引两种,如果一条sql语句操作了
主键索引,MySQL就会锁定这条主键索引;如果一 条语句操作了非主键索引,MySQL会先锁定该非主键索引,再锁定相关的主键索引。
在UPDATE、DELETE操作时,MySQL不仅锁定WHERE条件扫描过的所有索引记录,而且会锁定相邻的键值,即所谓的next-key locking
(2) 把死锁信息写入到error.log。
set global innodb_print_all_deadlocks = 1;
mysql innodb 死锁_mysql innodb 死锁分析相关推荐
- mysql 表死锁_MySQL Innodb表导致死锁日志情况分析与归纳
案例描述在定时脚本运行过程中,发现当备份表格的sql语句与删除该表部分数据的sql语句同时运行时,mysql会检测出死锁,并打印出日志. 两个sql语句如下:(1)insert into backup ...
- mysql for update死锁_Mysql 数据库死锁过程分析(select for update)
近期有一个业务需求,多台机器需要同时从Mysql一个表里查询数据并做后续业务逻辑,为了防止多台机器同时拿到一样的数据,每台机器需要在获取时锁住获取数据的数据段,保证多台机器不拿到相同的数据. 我们My ...
- mysql 释放空间_Mysql InnoDB删除数据后释放磁盘空间的步骤详解
Mysql InnoDB删除数据后释放磁盘空间的方法 Innodb数据库对于已经删除的数据只是标记为删除,并不真正释放所占用的磁盘空间,这就导致InnoDB数据库文件不断增长. 如果在创建数据库的时候 ...
- mysql uuid 性能_mysql InnoDB UUID 主键 性能优化【性能分析篇】.md
Benchmarking 主键字段的三种存储方式 events_uuid – UUID binary(16) PRIMARY KEY events_int – 自增序列bigint(20) NOT N ...
- mysql innodb 锁_MySQL/InnoDB锁机制
显式加锁 select ... lock in share mode:加 S 锁 select ... for update:加 X 锁 MySQL快照读和当前读 在一个支持MVCC并发控制的系统中, ...
- mysql 插入加锁_MySQL的死锁系列- 锁的类型以及加锁原理
疫情期间在家工作时,同事使用了 insert into on duplicate key update 语句进行插入去重,但是在测试过程中发现了死锁现象: ERROR 1213 (40001): De ...
- mysql 索引原理_MySQL InnoDB索引原理和算法
也许你经常用MySQL,也会经常用索引,但是对索引的原理和高级功能却并不知道,我们在这里一起学习下. InnoDB存储索引 在数据库中,如果索引太多,应用程序的性能可能会受到影响:如果索引太少,又会对 ...
- mysql阻塞 事务_MySQL Innodb如何找出阻塞事务源头SQL
在MySQL数据库中出现了阻塞问题,如何快速查找定位问题根源?在实验开始前,咱们先梳理一下有什么工具或命令查看MySQL的阻塞,另外,咱们也要一一对比其优劣,由于有些命令可能在实际环境下可能并不适用. ...
- mysql innerdb 索引_mysql innodb索引原理
聚集索引(clustered index) innodb存储引擎表是索引组织表,表中数据按照主键顺序存放.其聚集索引就是按照每张表的主键顺序构造一颗B+树,其叶子结点中存放的就是整张表的行记录数据,这 ...
最新文章
- 全网把Map中的hash()分析的最透彻的文章,别无二家。
- 最强通道注意力来啦!金字塔分割注意力模块,即插即用,效果显著,已开源!...
- Tensorflow【实战Google深度学习框架】全连接神经网络以及可视化
- Ubuntu 16.04 LTS下编译GPU版tensorflow
- 二分图最大匹配 -- 匈牙利算法
- jquery拼接后css样式不生效_JQuery常用选择器以及操作属性和样式的方法介绍
- 轻松实现远程批量拷贝文件脚本(女学生作品)
- Linux(二) 常用命令和目录结构
- 牛客挑战赛47 A 一道GCD问题
- ruby 新建对象_Ruby中的面向对象编程
- 初中计算机网络的教案20分钟,初中网络安全教育教案
- 音创a55怎么安装系统_教您怎么用光驱重装系统,安装系统教程!
- 在matlab环境中实现图像的傅里叶变换,matlab用傅里叶变换实现图像的低通滤波
- 微软十月补丁星期二值得关注的0day及其它
- 【Visual C++】游戏开发笔记十三 游戏输入消息处理(二) 鼠标消息处理
- 康奈尔大学计算机科学人工智能,美国康奈尔大学工程学院申请之计算机科学
- 怎么用transmac制作mac安装盘|transmac制作苹果系统启动U盘方法
- 如何在excel中实现数据的转置(行列互换)
- JS基础知识(二十八):箭头函数
- 前缀、中缀、后缀表达式及中缀转后缀表达式
热门文章
- 大数据批量插入小练习_SqlServer
- 实战演示 bacula 软件备份功能
- 继续泼冷水 Ubuntu决定放弃支持安腾
- MEncoder 使用实例
- Linux使用RSA实现免密登录(原理)
- webgl获取鼠标形状_三模无线搭配对称手型设计,游戏致胜利器,ROG烈刃2无线鼠标...
- ubantu安装pycharm破解+Linux基础简介
- 【python】list append()和extend()区别
- 八大排序算法:插入(2:插入、希尔)、选择(2:选择、堆)、交换(2:冒泡、快速)、归并、基数
- 在python中模块可以封装_python 制作python包,封装成可用模块教程