How to stop a running procedure in MySQL?

licaomeng picture licaomeng · Nov 23, 2015 · Viewed 11.3k times · Source

I called a procedure in MySQL, but it is in an endless loop now! How to stop a running procedure in MySQL? The following is my procedure code:

drop procedure if exists my_proc; 
DELIMITER $$
CREATE PROCEDURE my_proc
()
BEGIN
DECLARE VAR INT;
SET VAR=0;
WHILE VAR<10000
DO
INSERT INTO my_table () VALUES ();
END WHILE;
END; $$
DELIMITER;

CALL my_proc();

Answer

maxhb picture maxhb · Nov 23, 2015

Connect to the server (or use phpmyadmin or something similar) and do:

SHOW PROCESSLIST;

Find the process causing trouble, note its ID and do:

KILL ID_OF_YOUR_PROCESS;