SHOW VARIABLES LIKE 'max_connections';
-- 默認 151 (5.7+) 或 100 (舊版),上限 16384
SET GLOBAL max_connections = 1000;
SHOW VARIABLES LIKE 'max_connections'; -- 驗證
適用:臨時突發流量、無重啟權限場景。
[mysqld]
max_connections = 1000
# 伴隨參數建議同步調大
open_files_limit = 65535
table_open_cache = 4000
innodb_open_files = 4000
重啟生效:systemctl restart mysqld
編輯 /usr/local/mysql/bin/mysqld_safe,在 mysqld 啟動行追加:
-O max_connections=1500
⚠️ MySQL 5.7+ -O 參數已棄用,**強烈建議用方案二**。
| 參數 | 建議值 | 說明 |
|---|---|---|
| open_files_limit | 65535 | 系統文件句柄上限,需 ulimit -n 配合 |
| table_open_cache | 4000+ | 表緩存,避免頻繁打開關閉 |
| innodb_open_files | 4000+ | InnoDB 表句柄緩存 |
| thread_cache_size | 100+ | 線程緩存,減少創建銷毀開銷 |
| back_log | 200+ | 監聽隊列,應對突發連接 |