The Community Forums

Interact with an entire community of cPanel & WHM users!
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

need bash script to kill slow queries running more than x minutes

Discussion in 'Workarounds and Optimization' started by bhanuprasad1981, Apr 14, 2012.

  1. bhanuprasad1981

    bhanuprasad1981 Well-Known Member

    Joined:
    Aug 5, 2008
    Messages:
    222
    Likes Received:
    0
    Trophy Points:
    16
    Location:
    India
    hi i need a bash script which can auto kill slow queries running more than x minutes or seconds sometimes i need to wakeup at night to kill such queries or reboot server , something which can be run by cron can be helpfull.
     
  2. stdout

    stdout Well-Known Member

    Joined:
    Apr 10, 2003
    Messages:
    189
    Likes Received:
    5
    Trophy Points:
    18
    Location:
    Nelspruit, Mpumalanga, South Africa
    cPanel Access Level:
    Root Administrator
    Prematurely killig mySQL queries can lead to data loss/corruption.

    5 minute cronjob that processes the mySQL process list,kills any queries running more than 60 secs and then logs to /var/log/mysql_kills.log

     
  3. bhanuprasad1981

    bhanuprasad1981 Well-Known Member

    Joined:
    Aug 5, 2008
    Messages:
    222
    Likes Received:
    0
    Trophy Points:
    16
    Location:
    India
    i get errors in crontab file, can't install.
     
  4. stdout

    stdout Well-Known Member

    Joined:
    Apr 10, 2003
    Messages:
    189
    Likes Received:
    5
    Trophy Points:
    18
    Location:
    Nelspruit, Mpumalanga, South Africa
    cPanel Access Level:
    Root Administrator
    you have the keys... unlock the door... diagnose
     
  5. bhanuprasad1981

    bhanuprasad1981 Well-Known Member

    Joined:
    Aug 5, 2008
    Messages:
    222
    Likes Received:
    0
    Trophy Points:
    16
    Location:
    India
    i am unable to solve what is error in above command please help :s
     
  6. cPanelTristan

    cPanelTristan Quality Assurance Analyst
    Staff Member

    Joined:
    Oct 2, 2010
    Messages:
    7,623
    Likes Received:
    21
    Trophy Points:
    38
    Location:
    somewhere over the rainbow
    cPanel Access Level:
    Root Administrator
    Is there a reason you do not locate the slow queries by enabling the slow query log and then try to index or optimize them rather than taking the route you are trying to take? Killing off slow queries is a very bad idea. That's why MySQL has no option to stop a query once it's been executed.
     
Loading...

Share This Page