There are two way,
1.Use MAX_EXECUTION_TIME hint in SQL as below.
mysql> select /*+ MAX_EXECUTION_TIME(1000) */ count(*) from tab1 a,tab1 b where a.cust_id = 3839203;
ERROR 3024 (HY000): Query execution was interrupted, maximum statement execution time exceeded
In the above SQL, there are no joins between both of table and having a huge amount of data. Hence it will take lots of time. But I have specified here to stop the query after running of 1000 ms or 1 sec.
- You can set a session parameter that accepts in milliseconds before running to this query. And once you want to reset the value you can specify the different values for it.
Before running your SQL
SET SESSION MAX_EXECUTION_TIME=1000;
Post running your SQL
SET SESSION MAX_EXECUTION_TIME= <<some different value or maximum value supported>>;