sa125 sa125 - 1 month ago 9
MySQL Question

MySQL - can I limit the maximum time allowed for a query to run?

I'm looking for a way to limit the max running time of a query on mysql server. I figured this could be done through the

configuration file, but couldn't find anything relevant in the docs. Anyone knows if this could be done? thanks.


There is no way to specify a maximum run time when sending a query to the server to run.

However, it is not uncommon to have a cron job that runs every second on your database server, connecting and doing something like this:

  2. Find all connections with a query time larger than your maximum desired time
  3. Run KILL [process id] for each of those processes