max_connections 設置過小(默認 151,舊版 100)mysql> SHOW VARIABLES LIKE 'max_connections';
+-----------------+-------+
| Variable_name | Value |
+-----------------+-------+
| max_connections | 100 |
+-----------------+-------+
mysql> SHOW GLOBAL STATUS LIKE 'Max_used_connections';
+----------------------+-------+
| Variable_name | Value |
+----------------------+-------+
| Max_used_connections | 5 |
+----------------------+-------+
Max_used_connections / max_connections ≈ 85%
max_connections 設太大,浪費記憶體[mysqld]
max_connections = 1000
wait_timeout = 600
interactive_timeout = 600
wait_timeout:非交互連接空閒 600 秒自動斷開,防泄漏interactive_timeout:交互式客戶端同理service mysqld restart(永久)SET GLOBAL max_connections = 1000;MySQL 保留 1 個 SUPER 權限連接槽,即使滿連也能用 root 登入排查:
mysql -u root -p -e "SHOW PROCESSLIST;" | grep -v Sleep | head -20
maxPoolSize ≤ max_connections * 0.8 / 實例數