MySQL 5.7新增sys.session表檢視系統執行狀態
阿新 • • 發佈:2018-12-30
在MySQL 5.6以前,我們通過show processlist\G命令檢視系統中正在執行的所有程序,從5.7開始,我們又可以通過sys.session表來檢視系統正在執行的所有程序,而且該表中的記錄相對processlist比較完善:
mysql> SELECT * from sys.session\G
*************************** 1. row ***************************
thd_id: 29
conn_id: 4
user: [email protected]
db: test
command: Query
state: alter table (read PK and internal sort)
time: 6
current_statement: ALTER TABLE b add index(b)
statement_latency: 5.78 s
progress: 19.19
lock_latency: 203.70 ms
rows_examined: 0
rows_sent: 0
rows_affected: 0
tmp_tables: 0
tmp_disk_tables: 0
full_scan: NO
last_statement: NULL
last_statement_latency: NULL
current_memory: 4.85 MiB
last_wait: wait/io/file/innodb/innodb_data_file
last_wait_latency: Still Waiting
source: fil0fil.cc:5623
trx_latency: 5.68 s
trx_state: ACTIVE
trx_autocommit: YES
pid: 23988
program_name: mysql
*************************** 2. row ***************************
thd_id: 28
conn_id: 3
user: [email protected]
db: test
command: Query
state: Sending data
time: 0
current_statement: insert into a select null, repeat('b', 255) from a
statement_latency: 303.54 ms
progress: NULL
lock_latency: 291.00 us
rows_examined: 0
rows_sent: 0
rows_affected: 0
tmp_tables: 1
tmp_disk_tables: 0
full_scan: NO
last_statement: NULL
last_statement_latency: NULL
current_memory: 1.43 MiB
last_wait: wait/io/table/sql/handler
last_wait_latency: Still Waiting
source: handler.cc:3056
trx_latency: 410.06 ms
trx_state: ACTIVE
trx_autocommit: YES
pid: 23969
program_name: mysql
*************************** 3. row ***************************
thd_id: 27
conn_id: 2
user: [email protected]
db: mysql
command: Query
state: Sending data
time: 0
current_statement: SELECT * from sys.session
statement_latency: 23.01 ms
progress: NULL
lock_latency: 10.02 ms
rows_examined: 0
rows_sent: 0
rows_affected: 0
tmp_tables: 4
tmp_disk_tables: 1
full_scan: YES
last_statement: NULL
last_statement_latency: NULL
current_memory: 3.25 MiB
last_wait: wait/synch/mutex/innodb/file_format_max_mutex
last_wait_latency: 31.69 ns
source: trx0sys.cc:781
trx_latency: 4.94 m
trx_state: ACTIVE
trx_autocommit: NO
pid: 23950
program_name: mysql
3 rows in set (0.20 sec)
我們從第1行的輸出可以看到,當前執行ALTER TABLE命令給一張表新增索引,還能讀出目前該語句的執行階段(目前正在讀PK和進行內部排序),並能顯示該命令完成的進度(19%),還包括當前執行的時間(5.78s)。
我們從第2行的輸出可以看到,當前在執行INSERT操作,這是一個自動提交的事務,已經運行了410.06毫秒,我們甚至可以從中讀到,需要一個臨時表來執行該語句。
我們從第3行的輸出可以看到,從執行SELECT * FROM sys.session開始到現在有一個事務已經持續了4.94分鐘。
mysql> SELECT * from sys.session\G
*************************** 1. row ***************************
thd_id: 29
conn_id: 4
user: [email protected]
db: test
command: Query
state: alter table (read PK and internal sort)
time: 6
current_statement: ALTER TABLE b add index(b)
statement_latency: 5.78 s
progress: 19.19
lock_latency: 203.70 ms
rows_examined: 0
rows_sent: 0
rows_affected: 0
tmp_tables: 0
tmp_disk_tables: 0
full_scan: NO
last_statement: NULL
last_statement_latency: NULL
current_memory: 4.85 MiB
last_wait: wait/io/file/innodb/innodb_data_file
last_wait_latency: Still Waiting
source: fil0fil.cc:5623
trx_latency: 5.68 s
trx_state: ACTIVE
trx_autocommit: YES
pid: 23988
program_name: mysql
*************************** 2. row ***************************
thd_id: 28
conn_id: 3
user: [email protected]
db: test
command: Query
state: Sending data
time: 0
current_statement: insert into a select null, repeat('b', 255) from a
statement_latency: 303.54 ms
progress: NULL
lock_latency: 291.00 us
rows_examined: 0
rows_sent: 0
rows_affected: 0
tmp_tables: 1
tmp_disk_tables: 0
full_scan: NO
last_statement: NULL
last_statement_latency: NULL
current_memory: 1.43 MiB
last_wait: wait/io/table/sql/handler
last_wait_latency: Still Waiting
source: handler.cc:3056
trx_latency: 410.06 ms
trx_state: ACTIVE
trx_autocommit: YES
pid: 23969
program_name: mysql
*************************** 3. row ***************************
thd_id: 27
conn_id: 2
user: [email protected]
db: mysql
command: Query
state: Sending data
time: 0
current_statement: SELECT * from sys.session
statement_latency: 23.01 ms
progress: NULL
lock_latency: 10.02 ms
rows_examined: 0
rows_sent: 0
rows_affected: 0
tmp_tables: 4
tmp_disk_tables: 1
full_scan: YES
last_statement: NULL
last_statement_latency: NULL
current_memory: 3.25 MiB
last_wait: wait/synch/mutex/innodb/file_format_max_mutex
last_wait_latency: 31.69 ns
source: trx0sys.cc:781
trx_latency: 4.94 m
trx_state: ACTIVE
trx_autocommit: NO
pid: 23950
program_name: mysql
3 rows in set (0.20 sec)
我們從第1行的輸出可以看到,當前執行ALTER TABLE命令給一張表新增索引,還能讀出目前該語句的執行階段(目前正在讀PK和進行內部排序),並能顯示該命令完成的進度(19%),還包括當前執行的時間(5.78s)。
我們從第2行的輸出可以看到,當前在執行INSERT操作,這是一個自動提交的事務,已經運行了410.06毫秒,我們甚至可以從中讀到,需要一個臨時表來執行該語句。
我們從第3行的輸出可以看到,從執行SELECT * FROM sys.session開始到現在有一個事務已經持續了4.94分鐘。
從上可見,我們通過SELECT * FROM sys.session可以獲得更多的資訊。嘗試熟悉並習慣使用SELECT * FROM sys.session吧!
更多精彩MySQL內容 請關注我: