Skip to main content

KILL

Description

This statement is used to terminate a session.

info

If you have the PROCESS privilege, you can view all sessions. If you have the SUPER privilege, you can terminate all sessions and statements. Otherwise, you can only view and terminate your own sessions and statements.

Syntax

KILL [CONNECTION | QUERY] 'session_id'

Parameter description

ParameterDescription
KILL CONNECTIONLike the KILL statement without modifiers, it can terminate the given Client Session ID.
KILL QUERYIt can terminate the statement currently being executed, but keeps the connection in its original state.
session_idThe Client Session ID of the current session, which is the unique identifier for the session in the client. You can query it using the SHOW PROCESSLIST or SHOW FULL PROCESSLIST command.

Examples

Query the connected sessions and terminate the session.

  1. Query the connected sessions.

    SHOW PROCESSLIST;

    The returned result is as follows:

    +------------+------+----------------------+------+---------+-------+--------+------------------+
    | Id | User | Host | db | Command | Time | State | Info |
    +------------+------+----------------------+------+---------+-------+--------+------------------+
    | 3221487617 | root | xxx.xx.xxx.xxx:54284 | NULL | Sleep | 21560 | SLEEP | NULL |
    | 3221487619 | root | xxx.xx.xxx.xxx:21977 | test | Query | 0 | ACTIVE | SHOW PROCESSLIST |
    | 3221487628 | root | xxx.xx.xxx.xxx:58550 | NULL | Sleep | 9 | SLEEP | NULL |
    +------------+------+----------------------+------+---------+-------+--------+------------------+
    3 rows in set (0.023 sec)
  2. Terminate the session.

    KILL 3221487617;

References

For more information on how to query the number of sessions and their IDs in the current database, see View Tenant Sessions.