当前位置: 首页 > article >正文

mysql Kill脚本

背景描述

下面脚本用于在数据库阻塞情况下,紧急恢复.

Kill 某条sql

执行

sh kill.sh 或者sh kill.sh N(次数)

[J33FE0D ~]# cat kill_step1_oneSelect.sh
#!/bin/bash


# kill shwx processlist
# tony wnag


flag=$#

info='''----------------------------------
Argument is not corect
Reference:
sh kill.sh: kill one times
sh kill.sh $x: kill $1 times 
----------------------------------'''

case $flag in 
0)
        for x in `cat kill.list`
        do
            echo $x
            sh mha_manager.sh $x  "select concat('KILL ',id,';') from information_schema.processlist where user <> 'jd_mha_manager' and info like '%50793412%'"| egrep "KILL [0-9]" > /tmp/kill.sql
            mysql  -u jd_mha_manager -p'CmNuduFFYHLEw1P2' -A -P 3358 -h $x < /tmp/kill.sql
        done
;;
1)
        count=$1
        for xx in `seq 1 $count`
        do
            echo "kill time: $xx"
            for x in `cat kill.list`
            do
                echo $x
                sh mha_manager.sh $x  "select concat('KILL ',id,';') from information_schema.processlist where user <> 'jd_mha_manager' and info like '%select%'"| egrep "KILL [0-9]" > /tmp/kill.sql
                mysql  -u jd_mha_manager -p'CmNuduFFYHLEw1P2' -A -P 3358 -h $x < /tmp/kill.sql
            done
            sleep 1
        done
;;
*)
        echo $info
;;
esac

kill所有select

J33FE0D ~]# cat kill_step2_allSelect.sh
#!/bin/bash


# kill shwx processlist
# tony wnag


flag=$#

info='''----------------------------------
Argument is not corect
Reference:
sh kill.sh: kill one times
sh kill.sh $x: kill $1 times 
----------------------------------'''

case $flag in 
0)
        for x in `cat kill.list`
        do
            echo $x
            sh mha_manager.sh $x  "select concat('KILL ',id,';') from information_schema.processlist where user <> 'jd_mha_manager' and info like '%select%'"| egrep "KILL [0-9]" > /tmp/kill.sql
            mysql  -u jd_mha_manager -p'CmNuduFFYHLEw1P2' -A -P 3358 -h $x < /tmp/kill.sql
        done
;;
1)
        count=$1
        for xx in `seq 1 $count`
        do
            echo "kill time: $xx"
            for x in `cat kill.list`
            do
                echo $x
                sh mha_manager.sh $x  "select concat('KILL ',id,';') from information_schema.processlist where user <> 'jd_mha_manager' and info like '%select%'"| egrep "KILL [0-9]" > /tmp/kill.sql
                mysql  -u jd_mha_manager -p'CmNuduFFYHLEw1P2' -A -P 3358 -h $x < /tmp/kill.sql
            done
            sleep 1
        done
;;
*)
        echo $info
;;
esac

kill 所有连接(包括读写,空连接)

#!/bin/bash


# kill shwx processlist
# tony wnag


flag=$#

info='''----------------------------------
Argument is not corect
Reference:
sh kill.sh: kill one times
sh kill.sh $x: kill $1 times 
----------------------------------'''

case $flag in 
0)
        for x in `cat kill.list`
        do
            echo $x
            sh mha_manager.sh $x  "select concat('KILL ',id,';') from information_schema.processlist where user <> 'jd_mha_manager'"| egrep "KILL [0-9]" > /tmp/kill.sql
            mysql  -u jd_mha_manager -p'CmNuduFFYHLEw1P2' -A -P 3358 -h $x < /tmp/kill.sql
        done
;;
1)
        count=$1
        for xx in `seq 1 $count`
        do
            echo "kill time: $xx"
            for x in `cat kill.list`
            do
                echo $x
                sh mha_manager.sh $x  "select concat('KILL ',id,';') from information_schema.processlist where user <> 'jd_mha_manager'"| egrep "KILL [0-9]" > /tmp/kill.sql
                mysql  -u jd_mha_manager -p'CmNuduFFYHLEw1P2' -A -P 3358 -h $x < /tmp/kill.sql
            done
        done
;;
*)
        echo $info
;;
esac

Kill 慢SQL

Kill 执行时间超过2s的慢sql

J33FE0D ~]# cat kill_step7_slowSelect.sh
#!/bin/bash


# kill shwx processlist
# tony wnag


flag=$#

info='''----------------------------------
Argument is not corect
Reference:
sh kill.sh: kill one times
sh kill.sh $x: kill $1 times 
----------------------------------'''

case $flag in 
0)
        for x in `cat kill.list`
        do
            echo $x
            sh mha_manager.sh $x  "select concat('KILL ',id,';') from information_schema.processlist where user <> 'jd_mha_manager' and info like '%select%' and time > 2"| egrep "KILL [0-9]" > /tmp/kill.sql
            mysql  -u jd_mha_manager -p'CmNuduFFYHLEw1P2' -A -P 3358 -h $x < /tmp/kill.sql
        done
;;
1)
        count=$1
        for xx in `seq 1 $count`
        do
            echo "kill time: $xx"
            for x in `cat kill.list`
            do
                echo $x
                sh mha_manager.sh $x  "select concat('KILL ',id,';') from information_schema.processlist where user <> 'jd_mha_manager' and info like '%select%' and time > 2"| egrep "KILL [0-9]" > /tmp/kill.sql
                mysql  -u jd_mha_manager -p'CmNuduFFYHLEw1P2' -A -P 3358 -h $x < /tmp/kill.sql
            done
            sleep 1
        done
;;
*)
        echo $info
;;
esac


http://www.kler.cn/a/428930.html

相关文章:

  • 【QT】: 初识 QWidget 控件 | QWidget 核心属性(API) | qrc 文件
  • 与专业舆情优化公司合作是品牌化解舆情危机的重要途径
  • RabbitMQ--延迟队列
  • 无人机(Unmanned Aerial Vehicle, UAV)路径规划介绍
  • 如何在 Google Cloud Shell 中使用 Visual Studio Code (VS Code)?
  • Go入门学习笔记
  • 【干旱指数】非一致性干旱指数:SnsPI
  • 游戏引擎学习第34天
  • vscode通过ssh连接虚拟机进行开发
  • Next.js 系统性教学:深入理解缓存与数据优化策略
  • Spring07——AOP通知以及几个相关案例
  • 4.4 可靠传输的工作原理
  • 自然语言处理的未来愿景
  • 【Nacos03】消息队列与微服务之Nacos 集群部署
  • Android 还在使用LogCat打日志?XLog框架;日志打印到控制台,打印到文件中。
  • ES(elasticsearch)整合Spring boot使用实例
  • C—初阶结构体
  • 第23周:机器学习及文献阅读
  • 【postgresql初级使用】在表的多个频繁使用列上创建一个索引,多条件查询优化,多场景案例揭示索引失效
  • WEB_星河飞雪_Windows(全)
  • HCIA-Access V2.5_2_2网络通信基础_TCP/IP模型结构
  • Unity引擎UI滚动列表——滚动复用基础介绍
  • Javascript Clipper library, v6(介绍目录)
  • 六、隐语PIR功能及使用介绍
  • 漫画之家:基于Spring Boot的漫画社交网络平台
  • C# WPF抽奖程序