Terminate (kill) a specific session on MySQL server

MySQL provides a command to kill a specific session on a server.

Find session ID

First we will identify the session we want to end using any of the queries below:

Option 1 - Show statement

show processlist;

Option 2 - Generic query

select id,
    user,
    host,
    db,
    command,
    time,
    state,
    info
from information_schema.processlist;

Result

Kill session

Now we will use the session ID (Id) to kill a specific session (2 in this example):

kill 2;

Result

MySQL ends session and all operations associated with it are aborted if you are not using transactions. This operation could take a while.

Query OK, 0 rows affected (0.01 sec)
0
There are no comments. Click here to write the first comment.