KILL [CONNECTION | QUERY] processlist_id
Each connection to mysqld runs in a separate thread. 到mysqld
的每个连接都在一个单独的线程中运行。You can kill a thread with the 可以使用KILL
statement.processlist_id
kill processlist_id
语句终止线程。
Thread processlist identifiers can be determined from the 线程processlist标识符可以从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. 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
允许一个可选的CONNECTION
或QUERY
修饰符:
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.KILL CONNECTION
与不带修饰符的KILL
相同:它在终止连接正在执行的任何语句后,终止与给定processlist_id
关联的连接。
KILL QUERY
terminates the statement the connection is currently executing, but leaves the connection itself intact.KILL QUERY
终止连接当前正在执行的语句,但保持连接本身不变。
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
权限:
Without 如果不用CONNECTION_ADMIN
or SUPER
, you can kill only your own threads and statements.CONNECTION_ADMIN
或SUPER
,您只能终止自己的线程和语句。
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.CONNECTION_ADMIN
或SUPER
,您可以终止所有线程和语句,但要影响使用SYSTEM_USER
权限执行的线程或语句,您自己的会话还必须具有SYSTEM_USER
权限。
You can also use the mysqladmin processlist and mysqladmin kill commands to examine and kill threads.您还可以使用mysqladmin processlist
和mysqladmin 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
标志只在特定的时间间隔内进行检查:
During 在SELECT
operations, for ORDER BY
and GROUP BY
loops, the flag is checked after reading a block of rows. SELECT
操作期间,对于ORDER BY
和GROUP BY
循环,在读取一个行块后检查标志。If the kill flag is set, the statement is aborted.如果设置了kill标志,则语句将中止。
ALTER TABLE
operations that make a table copy check the kill flag periodically for each few copied rows read from the original table. ALTER TABLE
操作使表复制周期性地检查从原始表中读取的每几行复制的kill标志。If the kill flag was set, the statement is aborted and the temporary table is deleted.如果设置了kill标志,则语句将中止,临时表将被删除。
The KILL
statement returns without waiting for confirmation, but the kill flag check aborts the operation within a reasonably small amount of time. KILL
语句在不等待确认的情况下返回,但KILL标志检查会在合理的短时间内中止操作。Aborting the operation to perform any necessary cleanup also takes some time.中止操作以执行任何必要的清理也需要一些时间。
During 在UPDATE
or DELETE
operations, the kill flag is checked after each block read and after each updated or deleted row. UPDATE
或DELETE
操作期间,在每次读取块之后以及在每次更新或删除行之后检查kill
标志。If the kill flag is set, the statement is aborted. 如果设置了kill标志,则语句将中止。If you are not using transactions, the changes are not rolled back.如果不使用事务,则不会回滚更改。
GET_LOCK()
aborts and returns NULL
.GET_LOCK()
中止并返回NULL
。
If the thread is in the table lock handler (state: 如果线程在表锁处理程序中(状态:Locked
), the table lock is quickly aborted.Locked
),表锁将很快中止。
If the thread is waiting for free disk space in a write call, the write is aborted with a “disk full” error message.如果线程在写调用中等待可用磁盘空间,则写操作将被中止,并显示“磁盘已满”错误消息。
EXPLAIN ANALYZE
aborts and prints the first row of output. EXPLAIN ANALYZE
中止并打印第一行输出。This works in MySQL 8.0.20 and later.这适用于MySQL 8.0.20及更高版本。
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).任何对此类表的读取或写入操作都会失败,直到您再次优化或修复它(无中断)。