Instance 級共享,隨啟動分配,不隨連線數增長。核心七大組件:
| 組件 | 控制參數 | 核心職責 | 關鍵監控指標 |
|---|---|---|---|
| 查詢緩存 | query_cache_size, query_cache_type | 緩存 SELECT 結果集,完全相同查詢秒回 | Qcache_hits / (Qcache_hits + Qcache_inserts) 命中率 |
| 線程緩存 | thread_cache_size | 緩存空閒線程,避免頻繁創建銷毀 | (Connections - Threads_created) / Connections 命中率 |
| 表緩存 | table_open_cache (5.1.3+) | 緩存表檔案句柄,減少 open/close 系統調用 | Opened_tables / Uptime 開啟頻率 |
| 表定義緩存 | table_definition_cache (5.1.3+) | 緩存 .frm 定義資訊,加速 DDL/查詢解析 | 大表數場景必調大(預設 256,上限 524288) |
| Binlog 緩衝 | binlog_cache_size, max_binlog_cache_size | 事務 Binlog 先寫記憶體,滿足 sync_binlog 條件再落盤 | 單事務超大觸發 Multi-statement transaction required more than 'max_binlog_cache_size' bytes |
| MyISAM 索引緩存 | key_buffer_size | 緩存 .MYI 索引塊,MyISAM 效能命門 | Key_reads / Key_read_requests 未命中率 |
| InnoDB Buffer Pool | innodb_buffer_pool_size | 緩存數據+索引頁,**InnoDB 效能核心** | (Innodb_buffer_pool_read_requests - Innodb_buffer_pool_reads) / Innodb_buffer_pool_read_requests 命中率 > 99% |
innodb_log_buffer_size (預設 16MB,建議 64-256MB)innodb_flush_log_at_trx_commit:
0:每秒刷檔 + 同步,**最高效能,掉電丟 1 秒**1(預設):**每次提交刷檔 + 同步,ACID 完全保障**2:每次提交刷檔,**不同步**,每秒同步一次,折中innodb_additional_mem_pool_size (5.6.3 後已廢棄,併入 Buffer Pool)# 全域共享
innodb_buffer_pool_size = 22G # 70% 物理記憶體
key_buffer_size = 256M # 僅 MyISAM 系統表
query_cache_size = 0 # 5.7+ 建議關閉,鎖爭用嚴重
query_cache_type = 0
thread_cache_size = 100
table_open_cache = 4000
table_definition_cache = 4000
binlog_cache_size = 4M
max_binlog_cache_size = 1G
innodb_log_buffer_size = 256M
innodb_flush_log_at_trx_commit = 1
# 線程專用(保守)
sort_buffer_size = 2M
join_buffer_size = 2M
read_buffer_size = 2M
read_rnd_buffer_size = 4M
tmp_table_size = 64M
max_heap_table_size = 64M
# 總量檢查:22G + 4000*(句柄/定義) + 100*(線程) + 連線數*16M < 32G
Opened_tables 斜率)innodb_log_write_requests vs 物理寫入)table_open_cache 過大 → 文件描述符耗盡 (open_files_limit 需同步調大)innodb_flush_log_at_trx_commit=1 是金融級預設,效能不足上電池備援 RAID 卡 (BBU/FBWC),而非降級為 0/2