RDS MySQL Kill 连接

Kill数据库查询

查看Query

show processlist;

Kill 查询

CALL mysql.rds_kill(processID);

Kill所有非系统连接

排除'admin', 'rdsadmin', 'rdsrepladmin', 'event_scheduler'用户

#!/bin/bash

read -p 'DB Password:' pass
# 替换localhost为对应的数据库连接地址
rds_host="localhost"
rds_user="admin01"
db="information_schema"

mysql_exec="mysql -u$rds_user -h$rds_host -p$pass -D$db -N -B"

exclude_system_user_cond="user not in('admin', 'rdsadmin', 'rdsrepladmin', 'event_scheduler')"
#user_cond="user='xxx'"
#time_cond="time > 1000"
#db_cond="db='testdb'"
#host_cond="host like '172.21.%'"
#command_cond="command='Query'"

kill_all_conn="select concat('CALL mysql.rds_kill(',id,');') from information_schema.processlist where $exclude_system_user_cond order by time desc;"

$mysql_exec -e "$kill_all_conn" | while read line
do
    # echo "$mysql_exec -e \"$line\""
    $mysql_exec -e "$line"
done

show processlist

慢查询日志 
mysqldumpslow mysql-slowquery.log.2022-07-20.11 > slow.txt
根据用户查询 
select * from information_schema.processlist where user='test_ro';
查询执行时间

根据连接从最开始执行命令开始到现在过去的时间查询(单位秒)

select * from information_schema.processlist where time>1000 order by time desc;
where条件排除系统用户 
where user not in('admin', 'rdsadmin', 'rdsrepladmin', 'event_scheduler')

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值