查看mysql数据库谁持有锁

一、全局锁
(1)经过 show processlist;
(2)查询视图performance_schema.metadatalocks
二、MDL锁
使用show processlist;语句查看线程信息时可能会发现State字段 值为“Waiting for table metadata lock”
show processlist;
(1)查询视图select from performance_schema.metadatalocks where OWNER_THREAD_ID!=sys.psthreadid(connection
id())\G
找出OWNER_THREAD_ID对应的ID
(2)select from performance_schema.events_statements_current where thread_id=48
三、表级锁
查询那个表级锁对应:OWNER_THREAD_ID
(1)select
from performance_schema.table_handles where OWNER_THREAD_ID!=0
查询对应sql
(2)select * from performance_schema.events_statements_current where thread_id=48
(3)查询内部id=48线程对应的进程
select processlist_id from performance_schema.threads where thread_id=48
(4)杀掉进程48
sql>kill 48
四、行级锁
information_schema.innodb_trx performance_schema.events_transactions_current
从MySQL 8.0开始,在performance_schema中提供了一个data_locks表 用于记录任意事务的锁信息(同时废弃了 information_schema.innodb_locks表),不须要有锁等待关系存在(注 意,该表中只记录InnoDB存储引擎层的锁)。
sys.innodb_lock_waits
是在MySQL 8.0中,该视图联结查询的表不一样(把以前版本中使用的
information_schema.innodb_locks表和information_schema.innodb_lockwaits表替换为 了performance schema.data_locks表和performance_schema.data_lock_waits表)。sql

相关文章
相关标签/搜索