MySQL 的 max_connections 可以设定 MySQL 服务器的最大连线数,但 max_connections 是针对整台 MySQL 服务器,如果某一个 MySQL 帐号使用过多连线数,可以用以下方法限制每个使用者最大连线数,限止因为个别高用量使用者拖累其他使用者。
另一个设定参数是 max_user_connections,就可以设定每个使用者的连线数量限制, 以避免一个使用者的用量过高而影响整台 MySQL 服务器的运作。一般上可以将 max_user_connections 设定成 max_connections 的一半数值, 例如 max_connections 是 1000, max_user_connections 可以设定成 500, 设定方法先开启 my.cnf:
# vi /etc/my.cnf
在 [mysqld] 段落加上 max_user_connections 的设定, 例如:
|
1 2 3 |
[mysqld] max_connections = 1000 max_user_connections = 500 |
上面设定了 max_connections 是 1000, max_user_connections 是 500.
储存盘案后需要重新启动 MySQL 才会生效:
# systemctl restart mysql
如果是 MariaDB, 要这样重新启动:
# systemctl restart mariadb