top of page
CerebroSQL

MySQL: 

KILL

Syntax:
KILL [CONNECTION | QUERY] processlist_id

Each connection to mysqld runs in a separate thread. You can kill a
thread with the KILL processlist_id statement.

Thread processlist identifiers can be determined from the ID column of
the INFORMATION_SCHEMA PROCESSLIST table, the Id column of SHOW
PROCESSLIST output, and the PROCESSLIST_ID column of the Performance
Schema threads table. The value for the current thread is returned by
the CONNECTION_ID() function.

KILL permits an optional CONNECTION or QUERY modifier:

o KILL CONNECTION is the same as KILL with no modifier: It terminates
the connection associated with the given processlist_id, after
terminating any statement the connection is executing.

o KILL QUERY terminates the statement the connection is currently
executing, but leaves the connection itself intact.

The ability to see which threads are available to be killed depends on
the PROCESS privilege:

o Without PROCESS, you can see only your own threads.

o With PROCESS, you can see all threads.

The ability to kill threads and statements depends on the
CONNECTION_ADMIN privilege and the deprecated SUPER privilege:

o Without CONNECTION_ADMIN or SUPER, you can kill only your own threads
and statements.

o With CONNECTION_ADMIN or SUPER, you can kill all threads and
statements, except that to affect a thread or statement that is
executing with the SYSTEM_USER privilege, your own session must
additionally have the SYSTEM_USER privilege.

You can also use the mysqladmin processlist and mysqladmin kill
commands to examine and kill threads

Example

bottom of page