The sys schema often formats the statement for readability, making it easier to spot the WHERE clause missing its index.
Before you can stop a query, you must find its unique (often referred to as a thread ID).
| Feature | KILL QUERY | KILL CONNECTION (or just KILL ) | |---------|--------------|------------------------------------| | Statement terminated | ✅ Yes | ✅ Yes | | Connection closed | ❌ No | ✅ Yes | | Transaction active? | Remains open (app must ROLLBACK) | Rolled back automatically | | Temporary tables | Dropped? No (kept for session) | Dropped (session ends) | | Locks held | Most released, but some may persist | All released | | Client reconnection required | No | Yes | | Use case | Kill runaway SELECT, stuck UPDATE | Kill idle connection, reset session |
KILL <thread_id>;
Killing a MySQL query can be a necessary step to restore the database to a healthy state. However, it's essential to exercise caution and follow best practices to minimize the risks. Always backup your database, use transactions, and monitor query performance to prevent long-running queries. If you need to kill a query, use the KILL command with caution and consider alternative methods if necessary.
Every database administrator or backend developer has been there. An application slows to a crawl, monitoring dashboards light up red, and users start complaining about timeouts. Somewhere in the database guts, a query is running wild, consuming resources like there is no tomorrow.
-- Show all active queries SHOW PROCESSLIST; mysql kill query
The syntax is simple, but the impact is significant.
Replace <thread_id> with the actual thread ID of the query you want to kill.
SELECT * FROM sys.processlist ORDER BY TIME DESC LIMIT 10; The sys schema often formats the statement for
Indicates if the query is "Sending data," "Searching rows," or "Locked". 2. The KILL QUERY Command
This kills the query and terminates the connection thread entirely.