KILL

The KILL statement is used to terminate a connection in any TiDB instance in the current TiDB cluster. Starting from TiDB v6.2.0, you can also use the KILL statement to terminate ongoing DDL jobs.

Synopsis

KillStmt

KILL [TIDB] - 图1

  1. KillStmt ::= 'KILL' 'TIDB'? ( 'CONNECTION' | 'QUERY' )? CONNECTION_ID

Examples

The following example shows how to get all active queries in the current cluster and terminate any one of them.

  1. SELECT ID, USER, INSTANCE, INFO FROM INFORMATION_SCHEMA.CLUSTER_PROCESSLIST;
  1. +---------------------+------+-----------------+-----------------------------------------------------------------------------+
  2. | ID | USER | INSTANCE | INFO |
  3. +---------------------+------+-----------------+-----------------------------------------------------------------------------+
  4. | 8306449708033769879 | root | 127.0.0.1:10082 | select sleep(30), 'foo' |
  5. | 5857102839209263511 | root | 127.0.0.1:10080 | select sleep(50) |
  6. | 5857102839209263513 | root | 127.0.0.1:10080 | SELECT ID, USER, INSTANCE, INFO FROM INFORMATION_SCHEMA.CLUSTER_PROCESSLIST |
  7. +---------------------+------+-----------------+-----------------------------------------------------------------------------+
  1. KILL 5857102839209263511;
  1. Query OK, 0 rows affected (0.00 sec)

MySQL compatibility

  • The KILL statement of MySQL can only terminate a connection in the currently connected MySQL instance, while the KILL statement of TiDB can terminate a connection in any TiDB instance in the entire cluster.
  • Currently, using the MySQL command line ctrl+c to terminate a query or connection in TiDB is not supported.

Behavior change descriptions

Starting from v6.1.0, TiDB supports the Global Kill feature, which is enabled by default and controlled by the enable-global-kill configuration.

Starting from v6.1.0, TiDB supports the Global Kill feature, which is enabled by default.

When the Global Kill feature is enabled, both KILL and KILL TIDB statements can terminate queries or connections across instances so you do not need to worry about erroneously terminating queries or connections. When you use a client to connect to any TiDB instance and execute the KILL or KILL TIDB statement, the statement will be forwarded to the target TiDB instance. If there is a proxy between the client and the TiDB cluster, the KILL and KILL TIDB statements will also be forwarded to the target TiDB instance for execution.

If the Global Kill feature is not enabled or you are using a TiDB version earlier than v6.1.0, note the following:

  • By default, KILL is not compatible with MySQL. This helps prevent against a case of a connection being terminated by a wrong TiDB server, because it is common to place multiple TiDB servers behind a load balancer. To terminate other connections on the currently connected TiDB instance, you need to add the TIDB suffix explicitly by executing the KILL TIDB statement.

  • It is STRONGLY NOT RECOMMENDED to set compatible-kill-query = true in your configuration file UNLESS you are certain that clients will be always connected to the same TiDB instance. This is because pressing ctrl+c in the default MySQL client opens a new connection in which KILL is executed. If there is a proxy between the client and the TiDB cluster, the new connection might be routed to a different TiDB instance, which possibly kills a different session by mistake.

  • The KILL TIDB statement is a TiDB extension. The feature of this statement is similar to the MySQL KILL [CONNECTION|QUERY] command and the MySQL command line ctrl+c. It is safe to use KILL TIDB on the same TiDB instance.

See also