SHOW STATUS 是 MySQL 內建的「儀表板」,能即時吐出數百項伺服器層級與會話層級的計數器。善用這些指標,可快速判斷資料庫是否健康、瓶頸在哪裡。本文將完整輸出結果分類解讀,並標出運維最關心的核心指標。
mysql> SHOW STATUS; +-----------------------------------+----------+ | Variable_name | Value | +-----------------------------------+----------+ | Aborted_clients | 0 | | Aborted_connects | 0 | | Bytes_received | 115 | | Bytes_sent | 180 | | Com_select | 1 | | Com_insert | 0 | | Com_update | 0 | | Com_delete | 0 | | Connections | 2 | | Created_tmp_tables | 1 | | Handler_read_key | 0 | | Handler_read_next | 0 | | Innodb_buffer_pool_pages_data | 67 | | Innodb_buffer_pool_pages_free | 2493 | | Innodb_buffer_pool_pages_total | 2560 | | Innodb_buffer_pool_read_requests | 635 | | Innodb_buffer_pool_reads | 16 | | Key_read_requests | 0 | | Key_reads | 0 | | Max_used_connections | 1 | | Open_tables | 6 | | Opened_tables | 0 | | Qcache_hits | 0 | | Queries | 2 | | Questions | 2 | | Slow_queries | 0 | | Threads_connected | 1 | | Threads_created | 1 | | Threads_running | 1 | | Uptime | 181 | +-----------------------------------+----------+
max_connections 設定是否足夠long_query_time 判斷是否需優化key_buffer_size 是否過大/過小tmp_table_size、max_heap_table_sizetable_open_cacheSELECT
VARIABLE_NAME,
VARIABLE_VALUE,
CASE
WHEN VARIABLE_NAME = 'Innodb_buffer_pool_read_requests' THEN @read_req := VARIABLE_VALUE
WHEN VARIABLE_NAME = 'Innodb_buffer_pool_reads' THEN @read_disk := VARIABLE_VALUE
END
FROM performance_schema.global_status
WHERE VARIABLE_NAME IN ('Innodb_buffer_pool_read_requests','Innodb_buffer_pool_reads');
SELECT 1 - @read_disk / @read_req AS buffer_pool_hit_rate;
SHOW STATUS 輸出龐大,但只要鎖定上述 20 個核心指標,即可覆蓋 90% 的日常巡檢與效能排查需求。建議寫成監控腳本定時采集,配合 Grafana/Prometheus 視覺化,做到趨勢可觀測、異常可告警。