MariaDB 数据库 “Error 1040 too many connection” 解决办法:MariaDB修改最大连接数

1.mariadb数据库最大连接数,默认是151

MariaDB [(none)]> show variables like 'max_connections';
+-----------------+-------+
| Variable_name   | Value |
+-----------------+-------+
| max_connections |  151  |
+-----------------+-------+

2.配置/etc/my.cnf

[mysqld]
...
max_connections=4096

3.重启数据库服务

systemctl restart mariadb 

4.重启mariadb服务,再次查看mariadb数据库最大连接数,最大连接数是214,并非我们设置的4096

MariaDB [(none)]> show variables like 'max_connections';
+-----------------+-------+
| Variable_name   | Value |
+-----------------+-------+
| max_connections |  214  |
+-----------------+-------+

5.因为mariadb有默认打开文件数限制,所以我们还要修改mariadb.service文件

vim /usr/lib/systemd/system/mariadb.service

[Service]
...
LimitNOFILE=10000
LimitNPROC=10000

6.重新加载系统服务,并重启mariadb服务

systemctl --system daemon-reload
systemctl restart mariadb.service

7.再次查看mariadb数据库最大连接数,可以看到最大连接数已经是4096

MariaDB [(none)]> show variables like 'max_connections';
+-----------------+-------+
| Variable_name   | Value |
+-----------------+-------+
| max_connections | 4096  |  
+-----------------+-------+

你可能感兴趣的:(linux,mysql,mysql,数据库,mariadb)