Always investigate why queries run long – missing indexes, bad query structure, lock contention, or just too much data. Killing is a band-aid, not a cure.
: You can query the information_schema.processlist table for similar information.
: This command lists the current running queries. You can filter by time to find queries that have been running for a long time.
#!/bin/bash
-- Usage CALL kill_long_running_queries(120); -- kills queries running > 2 minutes
Suppose you have a long running query with a thread id of 123 :