mariadb 常见问题

too many connections

客户端报错 too many connections,问题修复参考这里.

查看当前连接数限制

1
2
3
4
5
6
7
$ mysql -u root -p
> show variables like "max_connections";
+-----------------+-------+
| Variable_name | Value |
+-----------------+-------+
| max_connections | 214 |
+-----------------+-------+

临时配置

1
> set GLOBAL max_connections=1024;

永久配置

1
2
3
4
5
6
7
8
9
10
11
12
# step 1: 修改数据库最大连接数
# vim /etc/my.cnf
[mysqld]
# ...
max_connections=1024

# step 2: 修改 mariadb 默认打开文件数限制
# vim /usr/lib/systemd/system/mariadb.service
[Service]
# ...
LimitNOFILE=10000
LimitNPROC=10000