最近工作中经常出现因为mysql连接数导致的线程阻塞的各种问题,这里列举一下常用的查询mysql中数据库连接情况的sql,方便以后直接拿来使用。
-- 查看mysql支持的最大连接数
show variables like '%max_connections%';
-- 查看当前数据库的连接情况
show full processlist;
show processlist;
-- 查看当前连接中各个用户的连接数
select USER, count(*) from information_schema.processlist group by USER;
-- 查看各个IP的连接数
select SUBSTRING_INDEX(host,':',1) as ip , count(*) from information_schema.processlist group by ip;
-- 查看每一个用户的最大连接数
show variables like '%max_user_connections%';
-- 查看当前连接中连接时间最长的的连接
select host,user,time,state,info from information_schema.processlist order by time desc limit 10;
-- 查看数据库的连接配置
show variables like '%conn%';