您好,登錄后才能下訂單哦!
數(shù)據(jù)庫在出現(xiàn)鎖或者死鎖的時候,處理起來應(yīng)該綜合分析,應(yīng)該配合數(shù)據(jù)庫監(jiān)控系統(tǒng)、結(jié)合業(yè)務(wù)同時分析數(shù)據(jù)庫尋找問題,下面是一些常用的手動供參考:
參考參數(shù):
innodb_lock_wait_timeout
查看是否有表鎖?。?br/>
show OPEN TABLES where In_use > 0;
show processlist ;
select * from information_schema.`PROCESSLIST` where info is not null order by time desc ;
show engine innodb status;
或者查詢
SELECT * FROM INFORMATION_SCHEMA.INNODB_LOCKS;
SELECT * from INFORMATION_SCHEMA.INNODB_TRX;
SELECT * FROM INFORMATION_SCHEMA.INNODB_LOCK_WAITS;
應(yīng)該熟悉常用的表INNODB_LOCKS、INNODB_TRX、INNODB_LOCK_WAITS的一些字段含義,這樣可以快速的分析問題。
innodb_trx #當(dāng)前運行的所有事務(wù)
innodb_locks #當(dāng)前出現(xiàn)的鎖
innodb_lock_waits #鎖等待的對應(yīng)關(guān)系
其中show OPEN TABLES where In_use > 0;只能看到那些表被鎖??;
show processlist 看不到鎖的信息,判讀起來比較麻煩;
show engine innodb status; 可以查看到很多信息,特別是一些死鎖信息,但是分析起來比較麻煩。
下面為常用的sql語句供參考:
SELECT
r.trx_id waiting_trx_id,
r.trx_mysql_thread_Id waiting_thread,
r.trx_query waiting_query,
b.trx_id blocking_trx_id,
b.trx_mysql_thread_id blocking_thread,
b.trx_query blocking_query
FROM
information_schema.innodb_lock_waits w
INNER JOIN information_schema.innodb_trx b ON b.trx_id = w.blocking_trx_id
INNER JOIN information_schema.innodb_trx r ON r.trx_id = w.requesting_trx_id;
生成kill:
SELECT
r.trx_id waiting_trx_id,
r.trx_mysql_thread_Id waiting_thread,
r.trx_query waiting_query,
b.trx_id blocking_trx_id,
CONCAT('kill query ',b.trx_mysql_thread_id , ';'),
b.trx_query blocking_query
FROM
information_schema.innodb_lock_waits w
INNER JOIN information_schema.innodb_trx b ON b.trx_id = w.blocking_trx_id
INNER JOIN information_schema.innodb_trx r ON r.trx_id = w.requesting_trx_id;
根據(jù)查詢結(jié)果殺掉相應(yīng)的thread:
kill blocking_thread;
表對應(yīng)的字段含義參考:
SELECT
trx_id AS `事務(wù)ID`,
trx_state AS `事務(wù)狀態(tài)`,
trx_requested_lock_id AS `事務(wù)需要等待的資源`,
trx_wait_started AS `事務(wù)開始等待時間`,
trx_tables_in_use AS `事務(wù)使用表`,
trx_tables_locked AS `事務(wù)擁有鎖`,
trx_rows_locked AS `事務(wù)鎖定行`,
trx_rows_modified AS `事務(wù)更改行`
FROM
information_schema.innodb_trx ;
SELECT
lock_id AS `鎖ID`,
lock_trx_id AS `擁有鎖的事務(wù)ID`,
lock_mode AS `鎖模式 `,
lock_type AS `鎖類型`,
lock_table AS `被鎖的表`,
lock_index AS `被鎖的索引`,
lock_space AS `被鎖的表空間號`,
lock_page AS `被鎖的頁號`,
lock_rec AS `被鎖的記錄號`,
lock_data AS `被鎖的數(shù)據(jù)`
FROM
information_schema.innodb_locks;
SELECT
requesting_trx_id AS `請求鎖的事務(wù)ID`,
requested_lock_id AS `請求鎖的鎖ID`,
blocking_trx_id AS `當(dāng)前擁有鎖的事務(wù)ID`,
blocking_lock_id AS `當(dāng)前擁有鎖的鎖ID`
FROM
innodb_lock_waits;
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。