MySQL/MariaDB 数据库之 “Error 1040 too many connection” 解决办法:重启数据库或者修改最大连接数
第一种解决办法是重启数据库。
第二种解决办法修改最大连接数,步骤如下(以为 MariaDB 例):
1. 先登录
# mysql -u root -p
Enter password:
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 36
Server version: 5.5.60-MariaDB MariaDB Server
Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
2. 查询当前最大连接数数值
执行 select VARIABLE_VALUE from information_schema.GLOBAL_VARIABLES where VARIABLE_NAME='MAX_CONNECTIONS' 查询。
MariaDB [(none)]> select VARIABLE_VALUE from information_schema.GLOBAL_VARIABLES where VARIABLE_NAME='MAX_CONNECTIONS';
+----------------+
| VARIABLE_VALUE |
+----------------+
| 151 |
+----------------+
1 row in set (0.00 sec)
3. 修改最大连接数数值
执行 set global max_connections = <数值> 。
MariaDB [(none)]> set global max_connections = 3600;
Query OK, 0 rows affected (0.00 sec)
4. 再查询看是否修改成功
MariaDB [(none)]> select VARIABLE_VALUE from information_schema.GLOBAL_VARIABLES where VARIABLE_NAME='MAX_CONNECTIONS';
+----------------+
| VARIABLE_VALUE |
+----------------+
| 3600 |
+----------------+
1 row in set (0.00 sec)
修改成功!
注意,如果重启数据库,最大连接数又恢复以前的默认值。