数据库
首页 > 数据库> > MySQL:show process

MySQL:show process

作者:互联网

show processlist 显示用户正在运行的线程,需要注意的是,除了 root 用户能看到所有正在运行的线程外,其他用户都只能看到自己正在运行的线程,看不到其它用户正在运行的线程。除非单独个这个用户赋予了PROCESS 权限。

show processlist 显示的信息都是来自MySQL系统库 information_schema 中的 processlist 表。所以使用下面的查询语句可以获得相同的结果:

select * from information_schema.processlist limit 0, 10;

了解这些基本信息后,下面我们看看查询出来的结果都是什么意思。

下面我们单独看一下 Command 的值:

官方文档:https://dev.mysql.com/doc/refman/5.6/en/thread-commands.html

常用的相关sql语句:

按客户端 IP 分组,看哪个客户端的链接数最多

select client_ip,count(client_ip) as client_num from (select substring_index(host,':' ,1) as client_ip from processlist ) as connect_info group by client_ip order by client_num desc;

查看正在执行的线程,并按 Time 倒排序,看看有没有执行时间特别长的线程

select * from information_schema.processlist where Command != 'Sleep' order by Time desc;

找出所有执行时间超过 5 分钟的线程,拼凑出 kill 语句,方便后面查杀

select concat('kill ', id, ';') AS kill_str  from information_schema.processlist where Command != 'Sleep' and Time > 300 order by Time desc;

标签:语句,正在,show,process,线程,MySQL,processlist,执行,客户端
来源: https://www.cnblogs.com/smalldong/p/16359771.html