SQL:数据库进程排查

  1. show processlist; 显示用户正在运行的线程
  2. SELECT * FROM information_schema.processlist WHERE USER="root" AND db="logs_app";
  3. SELECT client_ip, COUNT(client_ip) AS client_count FROM (SELECT SUBSTRING_INDEX(HOST,':' ,1) AS client_ip FROM information_schema.processlist ) AS clients GROUP BY client_ip ORDER BY client_count DESC;
    取所有操作数据库的线程的客户端ip,计算其数量成表
  4. SELECT * FROM information_schema.processlist WHERE Command != 'Sleep' ORDER BY TIME DESC;
  5. SELECT CONCAT('kill ', id, ';') FROM information_schema.processlist WHERE Command != 'Sleep' AND TIME > 300 ORDER BY TIME DESC;
    找出状态不是sleep且时间超过5分钟的杀掉;
    Sleep通常代表资源未释放,如果是通过连接池,sleep状态应该恒定在一定数量范围内。
posted @ 2019-12-11 16:43  Adamanter  阅读(357)  评论(0编辑  收藏  举报