MySQL锁表查询不到进程,如何处理_mysql查看表占用但是查不到占用进程-程序员宅基地

技术标签: mysql  MySQL进阶  

背景

测试同事通过更新某个表的数据进行功能测试,突然说锁表了,也不知道原因为何,一直用的Navicat,然后用show OPEN TABLES where In_use > 0;命令也查询不到具体的进程ID

常规解决办法
  1. 查询是否锁表
show OPEN TABLES where In_use > 0;
  1. 查询进程
show processlist;

查询到相对应的进程,然后

kill id;
通过查看事务处理
  1. 查看正在锁的事务
SELECT * FROM INFORMATION_SCHEMA.INNODB_LOCKS;
  1. 查看等待锁的事务
SELECT * FROM INFORMATION_SCHEMA.INNODB_LOCK_WAITS;
通过Innodb处理

在MySQL中有一个方法可以探窥到锁情况,它会打印出所有innodb的信息:

SHOW ENGINE INNODB STATUS;

如下,是通过语句获取到的信息(其中的IP全部用10.10.10.10已替换),后面会简要的进行分析这段文本


=====================================
2019-12-18 11:44:35 7f4f743f4700 INNODB MONITOR OUTPUT
=====================================
Per second averages calculated from the last 5 seconds
-----------------
BACKGROUND THREAD
-----------------
srv_master_thread loops: 60826 srv_active, 0 srv_shutdown, 30696 srv_idle
srv_master_thread log flush and writes: 91522
----------
SEMAPHORES
----------
OS WAIT ARRAY INFO: reservation count 9916
OS WAIT ARRAY INFO: signal count 9842
Mutex spin waits 2763, rounds 43928, OS waits 1328
RW-shared spins 8532, rounds 255229, OS waits 8469
RW-excl spins 82, rounds 3658, OS waits 94
Spin rounds per wait: 15.90 mutex, 29.91 RW-shared, 44.61 RW-excl
------------
TRANSACTIONS
------------
Trx id counter 188109012
Purge done for trx's n:o < 188101227 undo n:o < 0 state: running but idle
History list length 684
LIST OF TRANSACTIONS FOR EACH SESSION:
---TRANSACTION 0, not started
MySQL thread id 2326, OS thread handle 0x7f4f743f4700, query id 915743 10.10.10.10 root init
SHOW ENGINE INNODB STATUS
---TRANSACTION 188109010, not started
MySQL thread id 2324, OS thread handle 0x7f4f74476700, query id 915731 10.10.10.10 yt_dev cleaning up
---TRANSACTION 0, not started
MySQL thread id 2321, OS thread handle 0x7f4f3c0ae700, query id 914695 10.10.10.10 root cleaning up
---TRANSACTION 0, not started
MySQL thread id 2319, OS thread handle 0x7f4f4014b700, query id 915351 10.10.10.10 root cleaning up
---TRANSACTION 188108991, not started
MySQL thread id 2277, OS thread handle 0x7f4f360f8700, query id 915671 10.10.10.10 ytdev_phsp_data cleaning up
---TRANSACTION 0, not started
MySQL thread id 2314, OS thread handle 0x7f4f35be4700, query id 912387 10.10.10.10 root cleaning up
---TRANSACTION 188108516, not started
MySQL thread id 2275, OS thread handle 0x7f4f745af700, query id 914221 10.10.10.10 ytdev_phsp_data cleaning up
---TRANSACTION 188108974, not started
MySQL thread id 2286, OS thread handle 0x7f4f40312700, query id 915594 10.10.10.10 yt_dev cleaning up
---TRANSACTION 0, not started
MySQL thread id 2287, OS thread handle 0x7f4f3c171700, query id 908400 10.10.10.10 ytdev_phsp_data cleaning up
---TRANSACTION 188108951, not started
MySQL thread id 2280, OS thread handle 0x7f4f74372700, query id 915501 10.10.10.10 yt_dev cleaning up
---TRANSACTION 188108970, not started
MySQL thread id 2276, OS thread handle 0x7f4f740e8700, query id 915576 10.10.10.10 ytdev_phsp_data cleaning up
---TRANSACTION 188108004, not started
MySQL thread id 2261, OS thread handle 0x7f4f741ec700, query id 915637 10.10.10.10 ytdev_phsp_data cleaning up
---TRANSACTION 188109011, not started
MySQL thread id 2259, OS thread handle 0x7f4f36139700, query id 915739 10.10.10.10 ytdev_phsp_data cleaning up
---TRANSACTION 188107491, not started
MySQL thread id 2251, OS thread handle 0x7f4f36076700, query id 908114 10.10.10.10 yt_dev cleaning up
---TRANSACTION 188105855, not started
MySQL thread id 2237, OS thread handle 0x7f4f35e6e700, query id 915667 10.10.10.10 ytdev_phsp_data cleaning up
---TRANSACTION 188106734, not started
MySQL thread id 2191, OS thread handle 0x7f4f3c0ef700, query id 904938 10.10.10.10 yttest_opr cleaning up
---TRANSACTION 188108971, not started
MySQL thread id 2220, OS thread handle 0x7f4f4018c700, query id 915685 10.10.10.10 ytdev_phsp_data cleaning up
---TRANSACTION 188109008, not started
MySQL thread id 2180, OS thread handle 0x7f4f3617a700, query id 915721 10.10.10.10 ytdev_phsp_data cleaning up
---TRANSACTION 188105318, not started
MySQL thread id 2132, OS thread handle 0x7f4f4020e700, query id 915614 10.10.10.10 ytdev_phsp_data cleaning up
---TRANSACTION 0, not started
MySQL thread id 2090, OS thread handle 0x7f4f74066700, query id 849932 10.10.10.10 ytdev_phsp_data cleaning up
---TRANSACTION 188108998, not started
MySQL thread id 1950, OS thread handle 0x7f4f402d1700, query id 915711 10.10.10.10 ytdev_phsp_data cleaning up
---TRANSACTION 188108968, not started
MySQL thread id 1747, OS thread handle 0x7f4f40088700, query id 915566 10.10.10.10 yttest_opr cleaning up
---TRANSACTION 188043721, not started
MySQL thread id 1376, OS thread handle 0x7f4f400c9700, query id 915665 10.10.10.10 ytdev_phsp_data cleaning up
---TRANSACTION 188106729, not started
MySQL thread id 21, OS thread handle 0x7f4f7416a700, query id 904903 10.10.10.10 yttest_opr cleaning up
---TRANSACTION 188108889, ACTIVE 39 sec starting index read
mysql tables in use 1, locked 1
LOCK WAIT 2 lock struct(s), heap size 360, 1 row lock(s)
MySQL thread id 2315, OS thread handle 0x7f4f74539700, query id 915249 10.10.10.10 root updating
UPDATE `ytphsp_busi_v2`.`app_evaluation` SET `is_visible`='1' WHERE `id`='26'
------- TRX HAS BEEN WAITING 39 SEC FOR THIS LOCK TO BE GRANTED:
RECORD LOCKS space id 5023 page no 3 n bits 104 index `PRIMARY` of table `ytphsp_busi_v2`.`app_evaluation` trx id 188108889 lock_mode X locks rec but not gap waiting
Record lock, heap no 31 PHYSICAL RECORD: n_fields 12; compact format; info bits 0
 0: len 8; hex 800000000000001a; asc         ;;
 1: len 6; hex 00000b363265; asc    62e;;
 2: len 7; hex 6100000228141d; asc a   (  ;;
 3: len 8; hex 800000000bebc201; asc         ;;
 4: len 4; hex 8000000f; asc     ;;
 5: len 4; hex 80000000; asc     ;;
 6: SQL NULL;
 7: len 4; hex 80000000; asc     ;;
 8: SQL NULL;
 9: SQL NULL;
 10: SQL NULL;
 11: SQL NULL;

------------------
---TRANSACTION 188101221, ACTIVE 3405 sec
2 lock struct(s), heap size 360, 1 row lock(s), undo log entries 2
MySQL thread id 2065, OS thread handle 0x7f4f35ca7700, query id 881823 10.10.10.10 ytdev_phsp_data cleaning up
Trx read view will not see trx with id >= 188101222, sees < 188101222
--------
FILE I/O
--------
I/O thread 0 state: waiting for completed aio requests (insert buffer thread)
I/O thread 1 state: waiting for completed aio requests (log thread)
I/O thread 2 state: waiting for completed aio requests (read thread)
I/O thread 3 state: waiting for completed aio requests (read thread)
I/O thread 4 state: waiting for completed aio requests (read thread)
I/O thread 5 state: waiting for completed aio requests (read thread)
I/O thread 6 state: waiting for completed aio requests (write thread)
I/O thread 7 state: waiting for completed aio requests (write thread)
I/O thread 8 state: waiting for completed aio requests (write thread)
I/O thread 9 state: waiting for completed aio requests (write thread)
Pending normal aio reads: 0 [0, 0, 0, 0] , aio writes: 0 [0, 0, 0, 0] ,
 ibuf aio reads: 0, log i/o's: 0, sync i/o's: 0
Pending flushes (fsync) log: 0; buffer pool: 0
146414 OS file reads, 68947 OS file writes, 48073 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 1556, seg size 1558, 17 merges
merged operations:
 insert 31, delete mark 15, delete 0
discarded operations:
 insert 0, delete mark 0, delete 0
Hash table size 138401, node heap has 187 buffer(s)
803.44 hash searches/s, 57.79 non-hash searches/s
---
LOG
---
Log sequence number 64441780891
Log flushed up to   64441780891
Pages flushed up to 64441780614
Last checkpoint at  64441780614
0 pending log writes, 0 pending chkp writes
21801 log i/o's done, 0.00 log i/o's/second
----------------------
BUFFER POOL AND MEMORY
----------------------
Total memory allocated 68681728; in additional pool allocated 0
Dictionary memory allocated 3026787
Buffer pool size   4096
Free buffers       1025
Database pages     2884
Old database pages 1044
Modified db pages  3
Pending reads 0
Pending writes: LRU 0, flush list 0, single page 0
Pages made young 9822, not young 3172429
0.00 youngs/s, 0.00 non-youngs/s
Pages read 143394, created 910, written 38680
0.00 reads/s, 0.00 creates/s, 0.00 writes/s
Buffer pool hit rate 1000 / 1000, young-making rate 0 / 1000 not 0 / 1000
Pages read ahead 0.00/s, evicted without access 0.00/s, Random read ahead 0.00/s
LRU len: 2884, unzip_LRU len: 0
I/O sum[30]:cur[0], unzip sum[0]:cur[0]
--------------
ROW OPERATIONS
--------------
0 queries inside InnoDB, 0 queries in queue
1 read views open inside InnoDB
Main thread process no. 1229, id 139978308536064, state: sleeping
Number of rows inserted 1171, updated 98547, deleted 974, read 21120891
0.00 inserts/s, 0.00 updates/s, 0.00 deletes/s, 863.03 reads/s
----------------------------
END OF INNODB MONITOR OUTPUT
============================

这里面最需要注意的一段就是如下这段,里面有死锁的事务ID,进程ID,能够进一步查询
搜寻这段的关键词:

  • TRX HAS BEEN WAITING
  • RECORD LOCKS space id
  • TRANSACTION
  • MySQL thread id
------- TRX HAS BEEN WAITING 39 SEC FOR THIS LOCK TO BE GRANTED:
RECORD LOCKS space id 5023 page no 3 n bits 104 index `PRIMARY` of table `ytphsp_busi_v2`.`app_evaluation` trx id 188108889 lock_mode X locks rec but not gap waiting
Record lock, heap no 31 PHYSICAL RECORD: n_fields 12; compact format; info bits 0
 0: len 8; hex 800000000000001a; asc         ;;
 1: len 6; hex 00000b363265; asc    62e;;
 2: len 7; hex 6100000228141d; asc a   (  ;;
 3: len 8; hex 800000000bebc201; asc         ;;
 4: len 4; hex 8000000f; asc     ;;
 5: len 4; hex 80000000; asc     ;;
 6: SQL NULL;
 7: len 4; hex 80000000; asc     ;;
 8: SQL NULL;
 9: SQL NULL;
 10: SQL NULL;
 11: SQL NULL;

------------------
---TRANSACTION 188101221, ACTIVE 3405 sec
2 lock struct(s), heap size 360, 1 row lock(s), undo log entries 2
MySQL thread id 2065, OS thread handle 0x7f4f35ca7700, query id 881823 10.10.10.10 ytdev_phsp_data cleaning up
Trx read view will not see trx with id >= 188101222, sees < 188101222

如上,可以找到事务ID=188101221,进程ID=2065
然后,kill 2065杀掉进程即可

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/Tomonkey/article/details/103595941

智能推荐

芯灵思Sinlinx A33开发板boa与CGI移植-程序员宅基地

文章浏览阅读346次。开发平台* 芯灵思SinlinxA33开发板淘宝店铺: https://sinlinx.taobao.com/嵌入式linux 开发板交流 641395230在嵌入式设备的管理与交互中,基于Web方式的应用成为目前的主流,这种程序结构也就是大家非常熟悉的B/S结构,即在 嵌入式..._cgi path_info boa

AudioES8374音频驱动调试_es8374 调试-程序员宅基地

文章浏览阅读6.9k次,点赞2次,收藏19次。 AudioES8374驱动模块调试 目录 Audio ES8374. 2 一、Audio ES8374文件建立与编译... 2 二、Audio ES8374原理图... 3 三、Audio ES8374相关配置... 3 四、Audio ES8374 I2C读写... 4..._es8374 调试

利用Vitis开发基于ZCU106的神经网络加速器(二)——DPU编译及Demo_dpu kernel编译工具是什么-程序员宅基地

文章浏览阅读4.4k次,点赞2次,收藏26次。前言上一篇文章讲到了如何生成可供Vitis使用的XRT platform。这次我们使用生成的platform来开发一个完整的加速器Demo并在ZCU06上跑通。DPU概述DPU是Vitis AI中官方提供的FPGA神经网络加速器,其架构如下图:DP(Deep Learning Processor Unit)是专用于卷积神经网络的可配置计算引擎。 引擎中使用的并行度是设计参数和应用程序。 它包含一组高度优化的指令,并支持大多数卷积神经网络,例如VGG,ResNet,GoogleNet,YOLO,SS_dpu kernel编译工具是什么

毕业论文图片格式、分辨率选择及高质量Word转PDF方法_什么格式的图像在word转pdf的时候损失小-程序员宅基地

文章浏览阅读1.8k次。毕业论文插图格式、分辨率选择及高质量Word转PDF方法_什么格式的图像在word转pdf的时候损失小

文件在线预览,支持各种文件类型,docker 离线发布kkFileview。_离线docker部署kkfile-程序员宅基地

文章浏览阅读681次。文件在线预览,docker离线安装,1分钟内即可搞定,word,ppt,excel纯开源,下载执行执行脚本,一步到位_离线docker部署kkfile

基于STM32CUBEMX驱动低压步进器电机驱动器STSPIN220(3)----定时器中断产生指定数量脉冲_stspin220 ref-程序员宅基地

文章浏览阅读1w次。在步进电机控制过程中,为了实现精确的位置和速度控制,经常需要输出指定数量的脉冲。这就需要使用定时器功能来生成PWM脉冲信号。本文将详细介绍如何利用STM32CUBEMX配置定时器以输出指定数量的PWM脉冲。定时器是STM32微控制器的一个重要功能模块,可用于生成各种定时和计数操作。通过合理配置定时器的参数和模式,我们可以实现精确的脉冲输出。_stspin220 ref

随便推点

了解 Xamarin.Forms 创建移动应用程序的基础知识 4 - Button_xaml语言 botton-程序员宅基地

文章浏览阅读229次。演示如何自定义 Button_xaml语言 botton

stm32资料库 6_stm ibis-程序员宅基地

文章浏览阅读1.1k次。PC端软件 1.DfuSe DfuSe——USB设备固件升级 ST扩展:包含PC端演示程序、调试演示程序和所有协议层源程序 2009年7月 DfuSe DfuSe——USB设备固件升级 ST扩展 程序包DfuSe DfuSe——USB设备固件升级 ST扩展 英文文档2.Flash loader demonstrator STM32F101xx和STM32F103xx闪存加载演示程序:包含PC端演示程序、命令行演示程序和头文件源码 20_stm ibis

GeoServer速成:安装启动,发布地图,加载QGIS_qgis geoserver-程序员宅基地

文章浏览阅读1.6k次,点赞2次,收藏11次。本节主题:Geoserver下载配置启动,发布地图,发布服务用QGIS查看。预计时间15分钟。练习数据位置:https://download.csdn.net/download/sinat_41310868/19362372视频教程见:https://www.bilibili.com/video/BV1Sg41137EZ/如果CSDN图片不清楚,请移步知乎:https://zhuanlan.zhihu.com/p/377826133一、下载配置启动访问http://geoserver_qgis geoserver

利用matlab构建自己的colormap(色彩搭配)_matlab colormap-程序员宅基地

文章浏览阅读10w+次,点赞170次,收藏698次。利用matlab构建自己的colormap这个博客是自己的第一篇博客,瞎写实验中。。。因为平时绘制多条曲线,多种颜色的散点图以及二维色彩图时,经常受colormap折磨,嫌弃matlab自带的太丑,自己想要的效果没有。所以这篇文章主要从RGB格式和HSV格式两种颜色模式去衡量构造颜色条。1.颜色模式首先说一下RBG格式,是通过对红(R)、绿(G)、蓝(B)三个颜色通道的变化以及..._matlab colormap

DolphinScheduler 2.0.5详解_apache-dolphinscheduler-2.0.5--程序员宅基地

文章浏览阅读1.7k次。大数据目前比较火爆的任务调度平台DolphinScheduler,一篇详细讲解DolphinScheduler的文档。DolphinScheduler 2.0.5详解涵盖DolphinScheduler介绍、系统架构,dolphinScheduler集群部署和DolphinScheduler的功能应用及DolphinScheduler问题解决方案等。_apache-dolphinscheduler-2.0.5-

学习STM32F769DK-OTA例程之百度云平台建立MQTT服务器-程序员宅基地

文章浏览阅读376次。@2019-04-17【小记】  百度云平台建立MQTT服务器时需要设置权限组,否则连接失败转载于:https://www.cnblogs.com/skullboyer/p/10722169.html_stm32 wifi mqtt 百度云

推荐文章

热门文章

相关标签