mysql连接报错:too many connections
排查问题
SHOW STATUS LIKE ‘Threads%’;
看到Threads_connected是当前连接数
show global VARIABLES LIKE ‘%max_connections%’;
查看当前最大连接数
此时连接数超过最大限制
可以通过
select * FROM information_schema.processlist
查到当前连接情况,可以看到好多连接时间都超过了半小时以上(time>60*30)
处理方式
临时调大连接数,治标不治本
set global max_connections=5000
限制连接超时时间
查看
SHOW global VARIABLES LIKE ‘%interactive_timeout%’;
SHOW global VARIABLES LIKE ‘%wait_timeout%’;
修改
set global interactive_timeout=1800;
set global wait_timeout=1800;
限制连接超时时间修改仅对新建链接有效,旧的链接需要手动kill
select * FROM information_schema.processlist where time >1800
取到所有半小时以上连接id,然后kill id即可