mysql Connection Number Setting Operation Method of Too many connections
- 2021-07-26 09:01:44
- OfStack
During the use of mysql, it was found that the number of connections exceeded ~ ~ ~ ~ ~
[root@linux-node1 ~]# mysql -u glance -h 192.168.1.17 -p
Enter password:
ERROR 1040 (08004): Too many connections
Solution, which is also the way to modify the number of mysql connections under centos7:
1) Temporary modifications
MariaDB [(none)]
>
show variables like "max_connections";
+-----------------+-------+
| Variable_name | Value |
+-----------------+-------+
| max_connections | 214 |
+-----------------+-------+
1 row in set (0.00 sec)
MariaDB [(none)]
>
set GLOBAL max_connections=1000;
Query OK, 0 rows affected (0.00 sec)
MariaDB [(none)]
>
show variables like "max_connections";
+-----------------+-------+
| Variable_name | Value |
+-----------------+-------+
| max_connections | 1000 |
+-----------------+-------+
1 row in set (0.00 sec)
2) Permanently modify:
Configuration/etc/my. cnf
[mysqld] Add a new line of the following parameters:
max_connections=1000
Restart the mariadb service and look at the maximum number of connections to the mariadb database again. You can see that the maximum number of connections is 214, not the 1000 we set.
MariaDB [(none)]
>
show variables like 'max_connections';
+-----------------+-------+
| Variable_name | Value |
+-----------------+-------+
| max_connections | 214 |
+-----------------+-------+
This is because mariadb has a default limit on the number of open files. You can increase the number of open files by configuration/usr/lib/systemd/system/mariadb. service.
Configuration/usr/lib/systemd/system/mariadb. service
[Service] Add two new lines of the following parameters:
LimitNOFILE=10000
LimitNPROC=10000
Reload the system service and restart the mariadb service
systemctl --system daemon-reload
systemctl restart mariadb.service
Looking at the maximum number of connections to the mariadb database again, you can see that the maximum number of connections is already 1000
MariaDB [(none)]
>
show variables like 'max_connections';
+-----------------+-------+
| Variable_name | Value |
+-----------------+-------+
| max_connections | 1000 |
+-----------------+-------+