aboutsummaryrefslogtreecommitdiff
path: root/sql/mywatch_kill.sql
blob: 07014673d4d50711b296218d2f00b730e2643d49 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
DELIMITER $$

DROP PROCEDURE IF EXISTS mysql.mywatch_kill $$
CREATE PROCEDURE mysql.mywatch_kill (IN i BIGINT)
  COMMENT 'Kill a query found in information_schema.processlist by ID'
-- It seems reasonable that this procedure kills the connection, not just
-- the query, because of the `DELETE` HTTP method on the process id. If the
-- connection is not killed, the process id remains.
BEGIN

  DECLARE n BIGINT;

  SELECT id INTO n
    FROM information_schema.processlist
    WHERE info IS NOT NULL
    AND host <> '' -- means non-system user
    AND id = i;

  IF (n IS NOT NULL) THEN
    KILL n; -- Use `CALL mysql.rds_kill(n);` on RDS
  END IF;

END $$

DELIMITER ;