接上一篇,未提交的事务导致锁等待,锁住一段时间后又提交了(也可能是回滚),锁释放业务继续运行。那么我们如何知道产生锁的事务是在跑什么SQL?
今天讲的这个工具,就可以通过监听3306端口的数据,把每个事务的起始时间,SQL命令都打印出来,而且可以设置事务时长,比如事务时长超过10秒的。
参考链接:https://highdb.com/%E8%BF%BD%E8%B8%AAmysql%E4%B8%AD%E9%95%BF%E6%97%B6%E9%97%B4%E8%BF%90%E8%A1%8C%E7%9A%84%E4%BA%8B%E5%8A%A1/
github链接:https://github.com/yoshinorim/MySlowTranCapture,下载后解压
#安装
How to use:
* Install libpcap, libpcap-devel, boost, and boost-devel if not installed
* make
* make install
* Run myslowtrancapture
#运行
[root@xxxx MySlowTranCapture-master]# myslowtrancapture -f "tcp port 3306"
Monitoring any interface..
Filtering rule: tcp port
Logging transactions that take more than milliseconds..
........开始等待符合条件的输出
#默认检测事务时长是4秒,我们构造一个显式事务,持续时间5秒,