Performance

MySQL:在單個查詢中獲取多個全域狀態和系統變數

  • October 17, 2019

當我們執行時SHOW global status;SHOW variables;我們會在結果集中獲得 291 和 278 條記錄的列表。從性能的角度來看,只有少數是非常重要的。在性能下降期間,我必須多次獲取這些變數。例如,我們可以將下面的多個語句寫成一個嗎?

show global status like 'Threads_cached';
show global status like 'Threads_connected';
show global status like 'Threads_created';
show global status like 'Threads_running';
show global status like 'Select_scan';

如果我們在單個語句中獲取這些變數,那將是一個很大的幫助……

select * from information_schema.GLOBAL_STATUS where VARIABLE_NAME like 'Threads_cached' or VARIABLE_NAME like 'Threads_connected' or VARIABLE_NAME like 'Threads_created' or VARIABLE_NAME like 'Threads_running' or VARIABLE_NAME like 'Select_scan';

請記住,在 MySQL 8 中,global_status 表已移至 performance_schema,因此您應該查詢:

SELECT * FROM performance_schema.global_status
WHERE VARIABLE_NAME like 'Open_files'
   OR VARIABLE_NAME like 'Uptime';

引用自:https://dba.stackexchange.com/questions/54953