Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8604147
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T02:29:56+00:00 2026-06-12T02:29:56+00:00

I want to check my MySQL server every minute and kill queries that have

  • 0

I want to check my MySQL server every minute and kill queries that have run longer than 150 seconds. The main reason I want to do this is because I don’t want queries from certain people to lock up the DB for everyone else. I know this is not the ultimate solution to the problem, but at least it’s a fallback in case something goes wrong with a query. I don’t have a slave DB (this is just an at-home project).

I’d like to schedule a script to run that does this for me. I’m unfamiliar with Perl or Ruby and I need it done on my Windows 2008 Server box. I’ve looked into creating a simple cmd line script, but that doesn’t seem to be possible. I know currently I can do something like this but I have to do it manually:

mysqladmin processlist
mysqladmin kill

Anyone have any ideas or examples on how I could do this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T02:29:57+00:00Added an answer on June 12, 2026 at 2:29 am

    If you have Wscript installed – I think it should be – you can try this. Save as “somethingorother.vbs” and execute every now and then. Or you can use the provided loop. Both loop and kill-for-real options are commented; test the script before uncommenting on a production server.

    I assume that ‘mysqladmin processlist’ outputs something like this (taken from my XP):

    +----+------+----------------+----+---------+------+-------+------------------+
    | Id | User | Host           | db | Command | Time | State | Info             |
    +----+------+----------------+----+---------+------+-------+------------------+
    | 21 | root | localhost:1648 |    | Query   | 0    |       | show processlist |
    +----+------+----------------+----+---------+------+-------+------------------+
    

    So we have to eliminate rows containing “—-” and rows containing “Id | User”, and what remains is

    | 21 | root | localhost:1648 |    | Query   | 0    |       | show processlist |
    

    which we can split by pipe signs ‘|’, getting nine fields from 0 to 8:

    0   1     2          3          4      5        6      7           8
     | 21 | root | localhost:1648 |    | Query   | 0    |       | show processlist |
    

    Field #1 is Id, and field #6 yields the run time.

    Option Explicit
    
    Dim objShell, objWshScriptExec, objStdOut, strLine
    Dim id, fields, rt, Killer, KillRun
    
    ' While True
    '     WScript.Sleep 150000
    
    Set objShell = CreateObject("WScript.Shell")
    Set objWshScriptExec = objShell.Exec("mysqladmin processlist")
    Set objStdOut = objWshScriptExec.StdOut
    
    While Not objStdOut.AtEndOfStream
       strLine = objStdOut.ReadLine
       If (InStr(strLine, "----") = 0 and InStr(strLine, "| Id | User |") = 0) Then
           fields = Split(strLine, "|")
           id = trim(fields(1))
           rt = trim(fields(6))
           If rt > 150 Then
               ' Set Killer = CreateObject("WScript.Shell")
               ' Set KillRun = objShell.Exec("mysqladmin kill " & id)
               echo 
           End If
       End If
    Wend
    
    ' Wend
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to check the log in MySQL to see the queries that are
I am new to MySQL and want to have InnoDB table type for my
I have the following tables in MySQL server: Companies: - UID (unique) - NAME
Say I want to check if a record in a MySQL table exists. I'd
I think I have a conflict between my knowledge on SQL Server and MySQL.
I want to store a php array as JSON in mysql. for that I
I want to begin writing queries in MySQL. show grants shows: +--------------------------------------+ | Grants
I don't want check if an item with a value exists in the arraylist,
I want to check which port is used, when the port is not explicitly
I want to check checkbox like $('#riderCheck').attr('checked','true') on some condition. but the problem is

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.