mysql的information_schema庫下有四張(實際上是系統檢視):innodb_locks、innodb_trx、innodb_lock_waits、processlist記錄了當前在mysql上的事務,執行緒,鎖的資訊。通過下面這條sql語句,可以查詢鎖與被鎖的事務或執行緒的資訊,語句如下:
use information_schema;
select a.trx_mysql_thread_id rl_thread_id, c.trx_mysql_thread_id hl_thread_id,
concat(d.user,'@',d.host,'::',d.db) rl_user_info, concat(e.user,'@',e.host,'::',e.db) hl_user_info,
'**********==' '**********==',
a.trx_id rl_trx_id, c.trx_id hl_trx_id,
a.trx_state rl_trx_state, c.trx_state rh_trx_state,
a.trx_operation_state rl_trx_operation_status, c.trx_operation_state hl_trx_operation_status,
a.trx_weight rl_trx_weight, c.trx_weight hl_trx_weight,
a.trx_started rl_trx_started, c.trx_wait_started rh_trx_wait_started,
a.trx_query rl_trx_query, c.trx_query hl_trx_query,
'**********==' '**********==',
f.lock_mode rl_lock_mode, g.lock_mode hl_lock_mode,
f.lock_type rl_lock_type, g.lock_type hl_lock_type,
f.lock_index rl_lock_index, g.lock_index hl_lock_index
from innodb_trx a, innodb_lock_waits b, innodb_trx c, processlist d, processlist e, innodb_locks f, innodb_locks g
where a.trx_id=b.requesting_trx_id
and c.trx_id=b.blocking_trx_id
and a.trx_mysql_thread_id=d.id
and c.trx_mysql_thread_id=e.id
and b.requested_lock_id=f.lock_id
and b.blocking_lock_id=g.lock_id \g
MySQL 鎖資訊檢視
檢視當前所有事務 select from information schema.innodb trx 檢視正在鎖的事務 select from information schema.innodb locks 檢視等待鎖的事務 select from information schema.innodb...
mysql8 0檢視鎖資訊
sys.innodb lock waits performance schema.events statements history performance schema.data locks performance schema.data locks wait performance schema...
MsSql檢視鎖資訊
檢視鎖資訊 create table t req spid int,obj name sysname declare s nvarchar 4000 rid int,dbname sysname,id int,objname sysname declare tb cursor for select ...