13.7.8.4 KILL Statement语句

KILL [CONNECTION | QUERY] processlist_id

Each connection to mysqld runs in a separate thread. mysqld的每个连接都在一个单独的线程中运行。You can kill a thread with the KILL processlist_id statement.可以使用kill processlist_id语句终止线程。

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. 线程processlist标识符可以从INFORMATION_SCHEMA PROCESSLIST表、SHOW PROCESSLIST输出的Id列和性能架构threads表的PROCESSLIST_ID列中确定。The value for the current thread is returned by the CONNECTION_ID() function.当前线程的值由CONNECTION_ID()函数返回。

KILL permits an optional CONNECTION or QUERY modifier:KILL允许一个可选的CONNECTIONQUERY修饰符:

The ability to see which threads are available to be killed depends on the PROCESS privilege:查看哪些线程可被终止的能力取决于PROCESS权限:

The ability to kill threads and statements depends on the CONNECTION_ADMIN privilege and the deprecated SUPER privilege:终止线程和语句的能力取决于CONNECTION_ADMIN权限和不推荐的SUPER权限:

You can also use the mysqladmin processlist and mysqladmin kill commands to examine and kill threads.您还可以使用mysqladmin processlistmysqladmin kill命令来检查和杀死线程。

When you use KILL, a thread-specific kill flag is set for the thread. 使用KILL时,会为线程设置特定于线程的kill标志。In most cases, it might take some time for the thread to die because the kill flag is checked only at specific intervals:在大多数情况下,线程可能需要一段时间才能终止,因为kill标志只在特定的时间间隔内进行检查:

Warning警告

Killing a REPAIR TABLE or OPTIMIZE TABLE operation on a MyISAM table results in a table that is corrupted and unusable. MyISAM表上终止修复表或优化表操作会导致表损坏且无法使用。Any reads or writes to such a table fail until you optimize or repair it again (without interruption).任何对此类表的读取或写入操作都会失败,直到您再次优化或修复它(无中断)。