MySQL之too many connections 解决方法

打开配置文件 添加一下配置 vim /etc/my.cnf

wait_timeout = 600
interactive_timeout = 600
max_connections=800

再次重启mysql即可
systemctl restart mysqld
原理解答

mysql 默认100 连接数,超过则连不上,实际工作的连接数远远没有100,大部分在sleep
所以要么增大连接数,要么杀掉无用连接,推荐后者。

我们可以先看看当前最大连接数是多少
show variables like '%max_connections%';
修改 max_connections=800
查看链接数 show processlist;

[root@ecs-dc15 etc]# systemctl stop mysqld
[root@ecs-dc15 etc]# systemctl start mysqld
[root@ecs-dc15 etc]# systemctl status mysqld
● mysqld.service - MySQL Server
   Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled)
   Active: active (running) since Thu 2020-07-30 11:50:32 CST; 2s ago
     Docs: man:mysqld(8)
           http://dev.mysql.com/doc/refman/en/using-systemd.html
  Process: 19046 ExecStart=/usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid $MYSQLD_OPTS (code=exited, status=0/SUCCESS)
  Process: 19028 ExecStartPre=/usr/bin/mysqld_pre_systemd (code=exited, status=0/SUCCESS)
 Main PID: 19050 (mysqld)
   CGroup: /system.slice/mysqld.service
           └─19050 /usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid

Jul 30 11:50:31 ecs-dc15 systemd[1]: Starting MySQL Server...
Jul 30 11:50:32 ecs-dc15 systemd[1]: Started MySQL Server.

 

你可能感兴趣的:(mysql)