当前位置:网站首页>行锁分析和死锁
行锁分析和死锁
2022-06-26 17:54:00 【 时光清浅ぴ许你安然】
一、行锁
通过检查InnoDB_row_lock状态变量来分析系统上的行锁的争夺情况:
show status like'innodb_row_lock%';
对各个状态量的说明如下:
Innodb_row_lock_current_waits: 当前正在等待锁定的数量
Innodb_row_lock_time: 从系统启动到现在锁定总时间长度
Innodb_row_lock_time_avg: 每次等待所花平均时间
Innodb_row_lock_time_max:从系统启动到现在等待最长的一次所花时间
Innodb_row_lock_waits:系统启动后到现在总共等待的次数
对于这5个状态变量,比较重要的主要是:
Innodb_row_lock_time_avg (等待平均时长)
Innodb_row_lock_waits (等待总次数)
Innodb_row_lock_time(等待总时长)
尤其是当等待次数很高,而且每次等待时长也不小的时候,我们就需要分析系统 中为什么会有如此多的等待,然后根据分析结果着手制定优化计划。
二、死锁
设置事务级为mysql默认的级别:
set tx_isolation='repeatable-read';
Session_1执行:
select * from account where id=1 for update;
Session_2执行:
select * from account where id=2 for update;

Session_1执行:
select * from account where id=2 for update;

Session_2执行:
select * from account where id=1 for update;

多数情况mysql可以自动检测死锁并回滚产生死锁的那个事务,但是有些情况 mysql没法自动检测死锁
查看近期死锁日志信息:
show engine innodb status\G;
边栏推荐
猜你喜欢
随机推荐
Using redis for user access data statistics hyperloglog and bitmap advanced data types
Daily record 2
我想知道,我在肇庆,到哪里开户比较好?网上开户是否安全么?
padding百分比操作
Detailed explanation of dos and attack methods
Problems encountered this week
RSA concept explanation and tool recommendation - LMN
Several key points in divorce agreement
Rich professional product lines, and Jiangling Ford Lingrui · Jijing version is listed
Applet setting button sharing function
Cloud native 02: Alibaba cloud cloud efficient flow pipeline
Comp281 explanation
VSCode使用 - Remote-SSH 配置说明
Live broadcast preview | how can programmers improve R & D efficiency? On the evening of June 21, the video number and station B will broadcast live at the same time. See you or leave!
Introduction to distributed cache / cache cluster
股票开账户如何优惠开户?现在在线开户安全么?
Leetcode daily [2022 - 02 - 16]
Lm06 the mystery of constructing the bottom and top trading strategy only by trading volume
并发之Synchronized说明
17.13 补充知识、线程池浅谈、数量谈、总结








