您的位置:首页 > 数据库 > MySQL

修改Mysql最大连接数

2020-12-25 10:08 1521 查看

最近使用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)
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: