aboutsummaryrefslogtreecommitdiff
path: root/sql
diff options
context:
space:
mode:
authorIgor Pashev <pashev.igor@gmail.com>2016-06-27 03:51:58 +0800
committerIgor Pashev <pashev.igor@gmail.com>2016-06-27 17:15:41 +0800
commita1617ebaeb256b3d359cc9fe389b8001235100c2 (patch)
tree4d7bcaf69b2987b333e52b072c08f4cb8230641e /sql
parent54f6dfb100d5ad817898d3f7cb13028b91bdecaf (diff)
downloadmywatch-a1617ebaeb256b3d359cc9fe389b8001235100c2.tar.gz
Allow killing queries
Diffstat (limited to 'sql')
-rw-r--r--sql/mywatch_kill.sql26
1 files changed, 26 insertions, 0 deletions
diff --git a/sql/mywatch_kill.sql b/sql/mywatch_kill.sql
new file mode 100644
index 0000000..0701467
--- /dev/null
+++ b/sql/mywatch_kill.sql
@@ -0,0 +1,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 ;
+