关于Mysql查看某个ip连接数及删除掉这个ip连接的方法

统计mysql各ip的连接总数:

mysql> select SUBSTRING_INDEX(host,‘:‘,1) as ip , count(*) from information_schema.processlist group by ip;

状态如下:

+----------------+----------+
| ip             | count(*) |
+----------------+----------+
|                |        3 | 
| 10.182.41.191  |        1 | 
| 10.190.249.204 |        1 | 
| 10.204.161.60  |       10 | 
| localhost      |        1 | 
+----------------+----------+

如ip10.190.249.204有一个进程正在连接mysql,我们要将其杀掉。

注:还有其他方法来查看mysql各ip连接总数,如在linux上通过mysql命令远程查看其状态。

mysql -u root -h127.0.0.1 -e "show processlist\G;"| egrep "Host\:" | awk -F: ‘{ print $2 }‘| sort | uniq -c

mysql -u root -h127.0.0.1 --skip-column-names -e "show processlist;"|awk ‘{print $3}‘|awk -F":" ‘{print $1}‘|sort|uniq –c

使用如下命令具体查看此ip的具体连接状态:

mysql> show full  processlist;

状态如下:

+--------+-----------------+----------------------+-----------------+-------------+----------+-----------------------------------------------------------------------+------------------------+
| Id     | User            | Host                 | db              | Command     | Time     | State                                                                 | Info                   |
+--------+-----------------+----------------------+-----------------+-------------+----------+-----------------------------------------------------------------------+------------------------+
|      1 | event_scheduler | localhost            | NULL            | Daemon      | 16664843 | Waiting on empty queue                                                | NULL                   | 
|      3 | tencentroot     | :34481               | NULL            | Sleep       |        5 |                                                                       | NULL                   | 
|     33 | tencentroot     | :38939               | NULL            | Binlog Dump | 16663717 | Master has sent all binlog to slave; waiting for binlog to be updated | NULL                   | 
| 460426 | tencentroot     | :45751               | NULL            | Sleep       |        2 |                                                                       | NULL                   | 
| 573982 | root            | 10.190.249.204:41661 | db_gfxy_gdb_239 | Sleep       |       24 |                                                                       | NULL                   | 
| 594340 | root            | 10.204.161.60:40129  | db_gfxy_gdb_239 | Sleep       |        6 |                                                                       | NULL                   | 
| 594341 | root            | 10.204.161.60:40130  | db_gfxy_gdb_239 | Sleep       |        7 |                                                                       | NULL                   | 
| 594342 | root            | 10.204.161.60:40131  | db_gfxy_gdb_239 | Sleep       |        6 |                                                                       | NULL                   | 
| 594343 | root            | 10.204.161.60:40132  | db_gfxy_gdb_239 | Sleep       |        6 |                                                                       | NULL                   | 
| 594344 | root            | 10.204.161.60:40133  | db_gfxy_gdb_239 | Sleep       |        6 |                                                                       | NULL                   | 
| 594345 | root            | 10.204.161.60:40134  | db_gfxy_gdb_239 | Sleep       |        6 |                                                                       | NULL                   | 
| 594346 | root            | 10.204.161.60:40135  | db_gfxy_gdb_239 | Sleep       |        6 |                                                                       | NULL                   | 
| 594347 | root            | 10.204.161.60:40136  | db_gfxy_gdb_239 | Sleep       |        6 |                                                                       | NULL                   | 
| 594348 | root            | 10.204.161.60:40137  | db_gfxy_gdb_239 | Sleep       |        6 |                                                                       | NULL                   | 
| 594349 | root            | 10.204.161.60:40138  | db_gfxy_gdb_239 | Sleep       |        6 |                                                                       | NULL                   | 
| 594402 | root            | 10.182.41.191:55110  | mysql           | Query       |        0 | NULL                                                                  | show full  processlist |

Ip:10.190.249.204对应的id为573982,直接杀掉其id:

mysql> kill 573982;

即杀掉10.190.249.204的连接。

时间: 2024-10-12 05:03:46

关于Mysql查看某个ip连接数及删除掉这个ip连接的方法的相关文章

mysql查看当前实时连接数

静态查看: SHOW PROCESSLIST; SHOW FULL PROCESSLIST; SHOW VARIABLES LIKE '%max_connections%'; SHOW STATUS LIKE '%Connection%'; 实时查看: mysql> show status like 'Threads%'; +-------------------+-------+ | Variable_name | Value | +-------------------+-------+ |

不管文件夹内有没有文件都删除掉这个文件夹的方法

1 <?php 2 //删除文件夹 3 //给我一个文件夹,删掉 4 5 ShanChu("./0307"); 6 function ShanChu($fname) 7 { 8 if(is_dir($fname)) 9 { 10 //在删除文件夹之前先把文件夹里面所有文件都删除调 11 $dir = opendir($fname); 12 while($dname = readdir($dir)) 13 { 14 if($dname!="." &&am

查看服务器IP连接数

1.查看服务器IP连接数: netstat -tun | awk '{print $5}' | cut -d: -f1 |sort | uniq -c | sort -nr 2.查看nginx日志一天访问量最多的前10位IP zcat access_nginx.api130.log.20160518.16.gz | awk '{print $1}' | sort | uniq -c | sort -nr -k1 |less

MySQL之表的创建、删除、修改、删除、查看及索引

创建数据库 create database|schema [if not exists] db_name [character set= ] [collate= ] 注:schema可以理解为方案或者数据库,与database一个意义 例创建一个students数据库,且默认字符集为'gbk'.默认排序为'gbk_chinese_ci'; create schema if not exists students character set 'gbk' collate 'gbk_chinese_c

MySQL 查看约束,添加约束,删除约束 添加列,修改列,删除列

ALTER TABLE:添加,修改,删除表的列,约束等表的定义. 查看列:desc 表名; 修改表名:alter table t_book rename to bbb; 添加列:alter table 表名 add column 列名 varchar(30); 删除列:alter table 表名 drop column 列名; 修改列名MySQL: alter table bbb change nnnnn hh int; 修改列名SQLServer:exec sp_rename't_stude

Mysql查看连接数相关信息

MySQL查看连接数相关信息在 数据库:INFORMATION_SCHEMA 表:PROCESSLIST 表结构如下: mysql> desc PROCESSLIST; +---------+-------------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +---------+-------------+------+-----+---------+-------+ | I

linux apache 查看IP连接数

查看Apache的连接数和当前的连接数以及IP访问次数,以下脚本可实现: #!/bin/bash#writen by zhuxiaowei#date:2015.10.19#about "watch clients IP "###########################################con_num=`netstat -ant | grep $ip:80 | wc -l`    # connections numbers con_now=`netstat -ant

mysql查看连接数排查问题

#mysql查看连接数SHOW VARIABLES LIKE '%max_connections%'; # max_connections 最大连接数 SHOW VARIABLES LIKE '%connection%';# PROCESSLIST; # 通过观察sql来判断.SHOW FULL PROCESSLIST SHOW PROCESSLIST; SHOW STATUS;SHOW PROCESSLIST#show extended-status; SHOW STATUS LIKE '%c

MySQL查看当前连接数、连接数和最大连接数

MySQL查看当前所有连接的详细资料: mysqladmin -u root -p processlist MySQL查看当前连接数(Threads为连接数) mysqladmin -u root -p status Uptime: 1047464  Threads: 22  Questions: 1494780  Slow queries: 0  Opens: 31357  Flush tables: 1  Open tables: 1981  Queries per second avg: