MySQL show processlist过滤

背景

有客户需要根据processlist做一些监控,需要用到过滤上面的操作。

根据某个用户过滤

mysql> select * from information_schema.processlist where User='UserName';
+----------+------------+---------------------+------+------------------+----------+------------------------------------------------------------------+------+
| ID       | USER       | HOST                | DB   | COMMAND          | TIME     | STATE                                                            | INFO |
+----------+------------+---------------------+------+------------------+----------+------------------------------------------------------------------+------+
| 18396093 | UserName | *.*.*.*:47712 | NULL | Binlog Dump GTID |  4608287 | Master has sent all binlog to slave; waiting for binlog to be up | NULL |
+----------+------------+---------------------+------+------------------+----------+------------------------------------------------------------------+------+
1 rows in set (0.00 sec)

杀死某些线程

mysql> select concat('kill ',ID,';') from information_schema.processlist where User='UserName';
+------------------------+
| concat('kill ',ID,';') |
+------------------------+
| kill 18396093;         |
| kill 22658331;         |
| kill 482;              |
+------------------------+
3 rows in set (0.00 sec)

监控统计每个用户的访问

mysql> select User,count(*) as cnt from information_schema.processlist group by user;
+-----------------+-----+
| User            | cnt |
+-----------------+-----+
| User1         | 168 |
| rep      |   1 |
| User2            |   2 |
+-----------------+-----+
3 rows in set (0.00 sec)

监控其他信息

凡是在processlist里面的都可以用来做过滤

mysql> show create table information_schema.processlist\G
*************************** 1. row ***************************
       Table: PROCESSLIST
Create Table: CREATE TEMPORARY TABLE `PROCESSLIST` (
  `ID` bigint(21) unsigned NOT NULL DEFAULT '0',
  `USER` varchar(16) NOT NULL DEFAULT '',
  `HOST` varchar(64) NOT NULL DEFAULT '',
  `DB` varchar(64) DEFAULT NULL,
  `COMMAND` varchar(16) NOT NULL DEFAULT '',
  `TIME` int(7) NOT NULL DEFAULT '0',
  `STATE` varchar(64) DEFAULT NULL,
  `INFO` longtext
) ENGINE=MyISAM DEFAULT CHARSET=utf8

参考

https://dev.mysql.com/doc/refman/5.7/en/show-processlist.html

https://dev.mysql.com/doc/refman/5.7/en/processlist-table.html

https://stackoverflow.com/questions/929612/how-to-customize-show-processlist-in-mysql

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值