數(shù)據(jù)庫(kù)在出現(xiàn)鎖或者死鎖的時(shí)候,處理起來(lái)應(yīng)該綜合分析,應(yīng)該配合數(shù)據(jù)庫(kù)監(jiān)控系統(tǒng)、結(jié)合業(yè)務(wù)同時(shí)分析數(shù)據(jù)庫(kù)尋找問(wèn)題,下面是一些常用的手動(dòng)供參考:
10年積累的網(wǎng)站設(shè)計(jì)制作、網(wǎng)站設(shè)計(jì)經(jīng)驗(yàn),可以快速應(yīng)對(duì)客戶(hù)對(duì)網(wǎng)站的新想法和需求。提供各種問(wèn)題對(duì)應(yīng)的解決方案。讓選擇我們的客戶(hù)得到更好、更有力的網(wǎng)絡(luò)服務(wù)。我雖然不認(rèn)識(shí)你,你也不認(rèn)識(shí)我。但先做網(wǎng)站設(shè)計(jì)后付款的網(wǎng)站建設(shè)流程,更有掇刀免費(fèi)網(wǎng)站建設(shè)讓你可以放心的選擇與我們合作。
參考參數(shù):
innodb_lock_wait_timeout
查看是否有表鎖住:
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;
或者查詢(xún)
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的一些字段含義,這樣可以快速的分析問(wèn)題。
innodb_trx #當(dāng)前運(yùn)行的所有事務(wù)
innodb_locks #當(dāng)前出現(xiàn)的鎖
innodb_lock_waits #鎖等待的對(duì)應(yīng)關(guān)系
其中show OPEN TABLES where In_use > 0;只能看到那些表被鎖??;
show processlist 看不到鎖的信息,判讀起來(lái)比較麻煩;
show engine innodb status; 可以查看到很多信息,特別是一些死鎖信息,但是分析起來(lái)比較麻煩。
下面為常用的sql語(yǔ)句供參考:
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ù)查詢(xún)結(jié)果殺掉相應(yīng)的thread:
kill blocking_thread;
表對(duì)應(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ù)開(kāi)始等待時(shí)間`,
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 `鎖類(lèi)型`,
lock_table AS `被鎖的表`,
lock_index AS `被鎖的索引`,
lock_space AS `被鎖的表空間號(hào)`,
lock_page AS `被鎖的頁(yè)號(hào)`,
lock_rec AS `被鎖的記錄號(hào)`,
lock_data AS `被鎖的數(shù)據(jù)`
FROM
information_schema.innodb_locks;
SELECT
requesting_trx_id AS `請(qǐng)求鎖的事務(wù)ID`,
requested_lock_id AS `請(qǐng)求鎖的鎖ID`,
blocking_trx_id AS `當(dāng)前擁有鎖的事務(wù)ID`,
blocking_lock_id AS `當(dāng)前擁有鎖的鎖ID`
FROM
innodb_lock_waits;