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')