查看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

相關文章
相關標籤/搜索