Shell Script to auto kill mysql sleep processes

后端 未结 5 758
别跟我提以往
别跟我提以往 2021-02-07 19:29

How We Kill mysql sleep processes Like:

+------+-----------+-----------+------------------------+---------+------+----------------+-----------------------------------         


        
5条回答
  •  Happy的楠姐
    2021-02-07 19:47

    Vishal's answer works well if you're running the command on the MySQL server, but it won't work if you're connecting to the server remotely or if you don't have permission to run SOURCE or SELECT ... INTO OUTFILE (eg. Amazon's RDS). It's possible to rewrite it not to rely on those features though, and then it'll work anywhere:

    mysql -h -u -p -e "SELECT CONCAT('KILL ',id,';') FROM information_schema.processlist WHERE Command = 'Sleep'" > sleep.txt
    cat sleep.txt | xargs -I% mysql -h -u -p -e "%"
    

提交回复
热议问题