服務器崩潰,日誌顯示「Too many connections」,發現預設 max_connections=100 遠低於實際需求。
vi /usr/local/mysql/bin/mysqld_safe
在兩處 mysqld 啟動命令末尾加入:
-O max_connections=1500
重啟驗證:
service mysqld restart
mysqladmin -uroot -p variables | grep max_connections
# 顯示 1500 即生效
vi sql/mysqld.cc
# 找到
{ "max_connections", OPT_MAX_CONNECTIONS,
"The number of simultaneous clients allowed.", (gptr*) &max_connections,
(gptr*) &max_connections, 0, GET_ULONG, REQUIRED_ARG, 100, 1, 16384, 0, 1, 0 },
# 將 100 改為 1500
./configure && make && make install
my.cnf [mysqld] 設定 max_connections=1500open_files_limit 與系統 ulimit -nThreads_connected 與 Max_used_connections 評估適當值