最近使用Mysql数据库进行多编程操作时报错:ERROR 1040: Too many connections 。提示连接过多,检查发现Mysql的默认连接数为151,可根据实际情况进行修改。
1、查看最大连接数设置
mysql -uroot -p
MariaDB [(none)]> show variables like ‘max_connections‘;
+-----------------+-------+
| Variable_name | Value |
+-----------------+-------+
| max_connections | 151 |
+-----------------+-------+
1 row in set (0.01 sec)
2、查看实际己使用的最大连接数
可以发现实际使用的连接数己达到最大连接数限制
MariaDB [(none)]> show global status like ‘Max_used_connections‘;
+----------------------+-------+
| Variable_name | Value |
+----------------------+-------+
| Max_used_connections | 152 |
+----------------------+-------+
1 row in set (0.01 sec)
3、根据实际需要修改最大连接数
MariaDB [(none)]> set GLOBAL max_connections=4096;
Query OK, 0 rows affected (0.00 sec)
MariaDB [(none)]> show variables like ‘max_connections‘;
+-----------------+-------+
| Variable_name | Value |
+-----------------+-------+
| max_connections | 4096 |
+-----------------+-------+
1 row in set (0.01 sec)
4、再次运行报错程序,检查己使用最大连接数
MariaDB [(none)]> show global status like ‘Max_used_connections‘;
+----------------------+-------+
| Variable_name | Value |
+----------------------+-------+
| Max_used_connections | 1002 |
+----------------------+-------+
1 row in set (0.01 sec)