script : kill slow MySQL queries




--muqodimah---

Hello everyone, this time i will share simple script to kill long query of MySQL. 
Based on of my experience, Long-running MySQL queries can bring down the whole database even before you react. One of the ways to keep the application running and debug long running query issues is by monitoring, logging and killing them. 
This will give a chance to keep application running while you debug to find out the issues. 
please use wisely.

 --1-- 

this script is to view how many query is runing
 ======================= 
#!/bin/bash 
#brekele.inc 
#by Darkonsole 
#^_^
 i="0" 
mysql -u root -pYOURPASSWORD -e 'show processlist\G' | egrep -b5 'Time: [1-9]{3,10}' | grep 'Id:'| cut -d':' -f2 | sed 's/^ //'| while read id 
do 
echo " $id" i=$[$i+1] 
done 
echo "jumlah Query lama $i" 

 sama@darKonsole:/var/www/kill$ ./mysql-show.sh
 jumlah Query lama 0 

 --2-- 

 now the importing thing, kill that damn query ( be brave .. ) 
 ------------ 
#!/bin/bash 
#brekele.inc 
#by Darkonsole 
#^_^ 
 mysql -u root -pYOURPASSWORD -e 'show processlist\G' | egrep -b5 'Time: [1-9]{3,10}' | grep 'Id:'| cut -d':' -f2 | sed 's/^ //'| while read id 
do 
echo $id; 
mysql -u root -pYOURPASSWORD -e "kill $id;" 
done 

 --end of story--

 /* Your warranty is now void. * 
* I am not responsible for bricked devices, dead service, 
* thermonuclear war, or you getting fired because the  app failed. 
*Please do some research if you have any concerns about this. 
* Do at your own risk 
*/
Previous
Next Post »

comment please ... ConversionConversion EmoticonEmoticon

Thanks for your comment