1. 在业务敏感度不高时,首先重启服务紧急处理
systemctl start mariadb #启动MariaDB
systemctl stop mariadb #停止MariaDB
systemctl restart mariadb #重启MariaDB
systemctl enable mariadb #设置开机启动
2. 现象原因: 有多个线程连接mysql服务,导致超出连接限制
3. 查看默认连接数
mysql
show variables like '%connection%';
可以看到返回为
max_connections 一般默认为 161
4. 修改方案, 要修改mysql的配置,然后重启mariadb服务,更新max_connections的值
4.1 查看mysql读取配置文件的顺序
mysql --help | grep my.cnf
按照路径可以选取第一个,如果没有可以新建文件。写入
[mysqld]
max_connections = 1000
4.2 配置/usr/lib/systemd/system/mariadb.service
[Service]新添加两行如下参数:
LimitNOFILE=10000
LimitNPROC=10000
4.3 重新加载系统服务,并重启mariadb服务
systemctl --system daemon-reload
systemctl restart mariadb
4.4 重复3的步骤,确认修改效果