Mysql: error 1040: Too many connections

2022/8/27 2:23:15

本文主要是介绍Mysql: error 1040: Too many connections,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

报错内容:

Mysql: error 1040: Too many connections

报错原因:

1、访问量过高,MySQL服务器抗不住,这个时候就要考虑增加从服务器分散读压力。
2、MySQL配置文件中max_connections值过小,默认为151。

解决方式一(永久生效):

1、进入查看服务最大连接数

MySQL [(none)]> show variables like 'max_connections';
+-----------------+-------+
| Variable_name   | Value |
+-----------------+-------+
| max_connections | 151   |
+-----------------+-------+
1 row in set (0.01 sec)

2、停止服务并修改配置

2.1 修改配置文件:

[root@localhost conf]# vi my.cnf
#在以下模块添加
[mysqld]
...
max_connections=1000    #调优最大连接数,默认151

2.2 重启服务

3、 再次查看

MySQL [(none)]> show variables like 'max_connections';
+-----------------+-------+
| Variable_name   | Value |
+-----------------+-------+
| max_connections | 1000  |
+-----------------+-------+
1 row in set (0.01 sec)

MySQL [(none)]> 

解决方式二(临时生效):

1、进入查看服务最大连接数

#默认最大连接数
mysql> show variables like '%max_connections%';
+-----------------+-------+
| Variable_name   | Value |
+-----------------+-------+
| max_connections | 151 |
+-----------------+-------+
1 row in set (0.00 sec)
 
#调整最大连接数
mysql> set global max_connections = 1000;
Query OK, 0 rows affected (0.00 sec)
 
#查看最大连接数
mysql> show variables like '%max_connections%';
+-----------------+-------+
| Variable_name   | Value |
+-----------------+-------+
| max_connections | 1000 |
+-----------------+-------+
1 row in set (0.00 sec)

 



这篇关于Mysql: error 1040: Too many connections的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!


扫一扫关注最新编程教程