SHOW GLOBAL STATUS LIKE 'Thread%';
+-------------------+-------+
| Variable_name | Value |
+-------------------+-------+
| Threads_connected | 107 | -- 當前活躍連接
| Threads_running | 104 | -- 正在執行查詢的連接
| Threads_created | 3252 | -- 歷史累計創建線程數
| Threads_cached | 0 | -- 當前緩存閒置線程
+-------------------+-------+
SHOW VARIABLES LIKE 'max_connections';
+-----------------+-------+
| Variable_name | Value |
+-----------------+-------+
| max_connections | 2000 | -- 允許上限
+-----------------+-------+
理想值:Max_used_connections / max_connections ≈ 85%
max_connections 設置過大,浪費內存(每連接預分配緩存)thread_cache_size 過小,建議設 32-64SHOW GLOBAL STATUS LIKE 'Max_used_connections';SET GLOBAL max_connections=3000;(重啟失效,需改配置文件)[mysqld]
max_connections = 3000
thread_cache_size = 64
max_connect_errors = 100000
wait_timeout = 600 # 空閒 10 分鐘斷開
interactive_timeout = 600
# 連接池建議:應用層配置 100-200,避免頻繁創建銷毀