MySQL: How to stop a running query?
There is a magic MySQL statement KILL which allows to terminate either connection or query associated with provided thread ID.
SHOW PROCESSLIST statement allows to see running threads (including thread ID).
Example 1:
KILL QUERY 24; |
terminates the statement that the connection is currently executing under thread 24, but leaves the connection itself intact.
Example 2:
KILL 24; |
or
KILL CONNECTION 24; |
terminates the connection associated with the thread 24 (i.e. re-connect will be required).