MySQL Innodb如何找出阻塞事務之定位問題

2021-10-06 11:57:57 字數 2571 閱讀 4468

#查詢 正在執行的事務:

select * from information_schema.innodb_trx;

#檢視正在鎖的事務

select * from information_schema.innodb_locks;

#檢視等待鎖的事務

select * from information_schema.innodb_lock_waits;

解說詳情日誌

show engine innodb status;
資料庫連線未關閉問題的過程 檢視

select * from performance_schema.threads where processlist_id=1227425559;

select * from performance_schema.threads where processlist_id=60178157;

select * from performance_schema.events_statememnts_current where thread_id =1227425559;

詳情鐵鏟部落格

#檢視某段時間以來未關閉事務

select

trx_id,

trx_started,

trx_mysql_thread_id

from

information_schema.innodb_trx

where

trx_started < date_sub(now(), interval 1 minute)

and trx_operation_state is null

and trx_query is null;

select * from information_schema.innodb_lock_waits;

#檢視未關閉的事務:

select

a.trx_id,

a.trx_state,

a.trx_started,

a.trx_query,

b.id,

b. user,

b. host,

b.db,

b.command,

b.time,

b.state,

b.info

from

information_schema.innodb_trx a

left join information_schema.processlist b on a.trx_mysql_thread_id = b.id

where

b.command = 'sleep';

引用瀟湘隱者的部落格

select b.trx_mysql_thread_id             as 'blocked_thread_id'

,b.trx_query as 'blocked_sql_text'

,c.trx_mysql_thread_id as 'blocker_thread_id'

,c.trx_query as 'blocker_sql_text'

,( unix_timestamp() - unix_timestamp(c.trx_started) )

as 'blocked_time'

from information_schema.innodb_lock_waits a

inner join information_schema.innodb_trx b

on a.requesting_trx_id = b.trx_id

inner join information_schema.innodb_trx c

on a.blocking_trx_id = c.trx_id

where ( unix_timestamp() - unix_timestamp(c.trx_started) ) > 4;

select a.sql_text,

c.id,

d.trx_started

from performance_schema.events_statements_current a

join performance_schema.threads b

on a.thread_id = b.thread_id

join information_schema.processlist c

on b.processlist_id = c.id

join information_schema.innodb_trx d

on c.id = d.trx_mysql_thread_id

where c.id=17

order by d.trx_started;

unknown table 'innodb_lock_waits' in information_schema

Mysql InnoDB如何保證事務

mysql儲存引擎innodb支援事務操作,即支援原子性 一致性 隔離性 永續性 acid 特性。下面介紹一下innodb是怎樣做到這幾個特性的。原子性 原子性是指事務中的語句要麼全部執行成功 要麼全部不執行,原子性是通過undo log實現的。永續性 永續性是指事務一旦提交,它對資料庫的改變就應該...

MySQL InnoDB 如何避免髒讀

事務隔離級別 repeatable read 能避免髒讀 rr隔離級別下的隱患 幻讀,另外一篇文章的重點 必須提前了解 當前讀和快照讀的區別 mysql 的 innodb 會維護一系列不暴露給使用者的隱藏字段,其中有3個用於實現快照讀 非阻塞讀 undo log 實現了快照讀的資料結構。read v...

如何找出最小偏向角 如何從大量資料中找出高頻詞?

有乙個 1gb 大小的檔案,檔案裡每一行是乙個詞,每個詞的大小不超過 16b,記憶體大小限制是 1mb,要求返回頻數最高的 100 個詞 top 100 由於記憶體限制,我們依然無法直接將大檔案的所有詞一次讀到記憶體中。因此,同樣可以採用分治策略,把乙個大檔案分解成多個小檔案,保證每個檔案的大小小於...