KILL [TIDB]

The statement KILL TIDB is used to terminate connections in TiDB.

Synopsis

KillStmt
KillOrKillTiDBCONNECTIONQUERYNUM
KillOrKillTiDB
KILLTIDB

Examples

mysql> SHOW PROCESSLIST; +------+------+-----------+------+---------+------+-------+------------------+ | Id | User | Host | db | Command | Time | State | Info | +------+------+-----------+------+---------+------+-------+------------------+ | 1 | root | 127.0.0.1 | test | Query | 0 | 2 | SHOW PROCESSLIST | | 2 | root | 127.0.0.1 | | Sleep | 4 | 2 | | +------+------+-----------+------+---------+------+-------+------------------+ 2 rows in set (0.00 sec)

You can get the TiDB Server details of a session to be killed by querying the INSTANCE column of INFORMATION_SCHEMA.CLUSTER_PROCESSLIST:

SELECT ID, USER, INSTANCE, INFO FROM INFORMATION_SCHEMA.CLUSTER_PROCESSLIST;
+---------------------+------+-----------------+-----------------------------------------------------------------------------+ | ID | USER | INSTANCE | INFO | +---------------------+------+-----------------+-----------------------------------------------------------------------------+ | 1 | root | 127.0.0.1:10082 | SELECT ID, USER, INSTANCE, INFO FROM INFORMATION_SCHEMA.CLUSTER_PROCESSLIST | | 2 | root | 127.0.0.1:10080 | | +---------------------+------+-----------------+------------------------------------------------------------- 2 rows in set (0.00 sec)

To execute the KILL TIDB statement, connect to the TiDB node where the session needs to be killed:

mysql -h 127.0.0.1 -P 10080 -u root -p
KILL TIDB 2; Query OK, 0 rows affected (0.00 sec)

MySQL compatibility

  • By design, KILL is not compatible with MySQL by default. This helps prevent against a case of a connection being terminated on the wrong TiDB server, because it is common to place multiple TiDB servers behind a load balancer.
  • DO NOT set compatible-kill-query = true in your configuration file UNLESS you are certain that clients will be always connected to the same TiDB node. This is because pressing ctrl+c in the default MySQL client opens a new connection in which KILL is executed. If there are proxies in between, the new connection might be routed to a different TiDB node, which possibly kills a different session.
  • 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 feature. It is safe to use KILL TIDB on the same TiDB node.

See also

Was this page helpful?