Purpose
You can use this statement to terminate a session.
Note
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 view and terminate only the sessions and statements that you have initiated.
Syntax
KILL [CONNECTION | QUERY] 'session_id'
Parameters
| Parameter | Description |
|---|---|
| KILL CONNECTION | It is equivalent to the KILL statement with no modifier and can be used to terminate a session specified by the client session ID. |
| KILL QUERY | Terminates the ongoing statement of the connection but retains the current status of the connection. |
| session_id | The client session ID of the current session, which is the unique identifier of a session in a client. You can execute the SHOW PROCESSLIST or SHOW FULL PROCESSLIST statement to obtain the session ID. |
Examples
Query and then terminate a session.
Query connected sessions.
obclient [test]> SHOW PROCESSLIST;The return 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 setTerminate a session.
obclient [test]> KILL 3221487617;
References
For more information about how to query the quantity and IDs of sessions in the current database, see View tenant sessions.