Linux – Assign a timeout period for MySQL queries

databaselinuxMySQL

Is there a way to assign a timeout period for MySQL queries, and limit them to say 60 seconds? I know its possible to do this when using a scripting language (eg, PHP). But is it possible to set a configuration in MySQL directly to prevent long running queries (typically selects in my case) from taking out the server?

NOTE: Running Mandriva, DB is in MyISAM, and this is for SELECT queries only.

Best Answer

One solution I typically do, if replication / slaves are not an option is this and you're trying to avoid long running report queries;

  • Assess which slow running SELECT queries are repeatedly executed
  • Turn the SELECT statements into report tables: CREATE TABLE report AS SELECT...
  • And fill the report tables nightly or whatever the case may be with a CRON job and that SELECT statement.

In this case your boss would be getting the data a lot quicker in the new report table(s). You probably have a good solution figured out already, but this could still be useful. :)