Lokas Software  
   
 

Mysql Kill Long Running Queries May 2026

KILL [CONNECTION] <id>; Or if you only want to terminate the current query but keep the connection:

How to Identify and Kill Long-Running Queries in MySQL mysql kill long running queries

SELECT CONCAT('KILL ', id, ';') AS kill_command FROM information_schema.processlist WHERE command != 'Sleep' AND time > 300; -- 5+ minutes Copy the output and run the commands. DELIMITER $$ CREATE PROCEDURE kill_long_running_queries(IN max_time_seconds INT) BEGIN DECLARE done INT DEFAULT FALSE; DECLARE pid INT; DECLARE cur CURSOR FOR SELECT id FROM information_schema.processlist WHERE command != 'Sleep' AND time > max_time_seconds; DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = TRUE; OPEN cur; read_loop: LOOP FETCH cur INTO pid; IF done THEN LEAVE read_loop; END IF; SET @kill_stmt = CONCAT('KILL ', pid); PREPARE stmt FROM @kill_stmt; EXECUTE stmt; DEALLOCATE PREPARE stmt; END LOOP; CLOSE cur; END$$ DELIMITER ; KILL [CONNECTION] &lt;id&gt;; Or if you only want

SET GLOBAL max_execution_time = 30000; -- milliseconds (30 seconds) Or per session/query: KILL [CONNECTION] &lt

-- Usage CALL kill_long_running_queries(120); -- kills queries running > 2 minutes Instead of just killing queries, prevent them from running too long:

Shopping Cart
Your cart is empty
Live Support
30 Day Money Back Guarantee
 
  Home Products Bundles Free Icons Download Order Support Distribution Articles Contacts Site Map
3D box, book cover mockup generator... Free icon sets, image to icon converter, favicon generator... Need a custom design? Icons, websites, boxshots, logotypes...
Copyright © 2000-2025 Lokas Software. All rights reserved. Terms of use and privacy policy info.