ERROR 1040 (HY000): Too many connections
max_connections 設定過小 → 參數調優SHOW VARIABLES LIKE 'max_connections'; -- 服務器允許上限 SHOW GLOBAL STATUS LIKE 'Max_used_connections'; -- 歷史峰值併發
使用率 = Max_used_connections / max_connections * 100% 理想區間:10% ~ 85% < 10% → 上限設過大,浪費內存 > 85% → 風險區,需擴容或調優
| 環境 | max_connections | Max_used_connections | 使用率 | 建議 |
|---|---|---|---|---|
| 本地測試 | 151 | 2 | 1.3% | 過大,可降至 50 |
| Linode VPS | 151 | 44 | 29% | 健康,保持或微調 |
SET GLOBAL max_connections = 256;
[mysqld] max_connections = 500 # 配套參數 wait_timeout = 60 thread_cache_size = 100 open_files_limit = 65535
修改後 systemctl restart mysqld。
wait_timeout:空閒連接回收時間,降低佔用thread_cache_size:緩存線程,減少創建銷毀開銷open_files_limit:配合大連接數調大文件描述符上限