MySql查詢正在進行中的事務

2022-01-17 03:04:59 字數 2271 閱讀 5328

select * from information_schema.innodb_trx

這個只能查詢此刻正在進行中的事務,已經完成的是查不到的

針對mysql 5.6,檢視更具體的資訊:

select a.trx_id, a.trx_state, a.trx_started, a.trx_query, b.id, b.user, b.db, b.command, b.time, b.state, b.info, c.processlist_user, c.processlist_host, c.processlist_db, d.sql_text from information_schema.innodb_trx a left join information_schema.processlist b on a.trx_mysql_thread_id = b.id and b.command = 'sleep' left join performance_schema.threads c on b.id = c.processlist_id left join performance_schema.events_statements_current d on d.thread_id = c.thread_id;

針對mysql 5.5,檢視更具體的資訊:

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 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;

the information_schema innodb_trx table

(1.會話1進行事務修改,修改耗時較長,在此過程中我們在另外會話來查詢

begin;

update salaries set salary = 61118 where emp_no % 7 = 0;

(耗時較長,迅速進行步驟2)

2.會話2查詢

3.會話1的事務結束後,(未提交)再到會話2查詢

(會話未結束,但已經沒有正在執行的sql語句)

4.提交會話1的事務

commit;

切換到會話2來查詢:

奮鬥正在進行中

不知不覺第二個專案已經接近了交工的期限。現在恨不得能有分身之術,乙個我在那緊鑼密鼓的敲著 乙個我在這和大家分享一下做專案的心得。在這緊張的時刻其他的都不多扯了,先和大家分享一下我們蝸牛三人組的專案狀況。我和鄭崗衛 高涵也可以說為了最初的夢想來到兄弟連,我們三個來自同一所大學同乙個班級。小高老師在專案...

mysql 查詢正在執行的語句

排查問題時,需要檢視正在執行的sql,可以用如下兩種方式進行檢視。1 使用show processlist,但是有個弊端,就是只能檢視正在執行的sql語句,對應歷史記錄,檢視不到。好處是不用設定,不會儲存。1 use information schema 2 show processlist 3或者...

mysql查詢正在執行的程序

檢視mysql程序有兩種方法 1.進入mysql bin目錄下輸入mysqladmin processlist 2.啟動mysql,輸入show processlist 如果有super許可權,則可以看到全部的執行緒,否則,只能看到自己發起的執行緒 這是指,當前對應的mysql帳戶執行的執行緒 my...