KILL [CONNECTION | QUERY]

You are viewing an old version of this article. View the current version here.

Syntax

KILL [HARD | SOFT] [CONNECTION | QUERY [ID] ] [thread_id | USER user_name | query_id]
MariaDB 5.3.2

The options HARD | SOFT and USER username were introduced in MariaDB 5.3.2

MariaDB 10.0.5

KILL QUERY ID query_id, which permits killing a query by query id rather than thread id, was introduced in MariaDB 10.0.5.

Description

Each connection to mysqld runs in a separate thread. You can see which threads are running with the SHOW PROCESSLIST statement and kill a thread with the KILL thread_id statement. KILL allows the optional CONNECTION or QUERY modifier:

  • KILL CONNECTION is the same as KILL with no modifier: It terminates the connection associated with the given thread or query id.
  • KILL QUERY terminates the statement that the connection thread_id is currently executing, but leaves the connection itself intact.
  • KILL QUERY ID (introduced in MariaDB 10.0.5) terminates the query by query_id, leaving the connection intact.

If you have the PROCESS privilege, you can see all threads. If you have the SUPER privilege, you can kill all threads and statements. Otherwise, you can see and kill only your own threads and statements.

The HARD option (default) kills a command ASAP. If you use SOFT, then critical operations that may leave a table in an inconsistent state will not be interrupted. Such operations are:

  • REPAIR and INDEX creation for MyISAM and Aria tables.

The timeouts generated by MAX_QUERY_TIME use KILL SOFT QUERY.

KILL ... USER username will kill all connections/queries for a given user. USER can be specified one of the following ways:

If you specify a thread id and that thread does not exist, you get the following error:

ERROR 1094 (HY000): Unknown thread id: <thread_id>

If you specify a query id that doesn't exist, you get the following error:

ERROR 1957 (HY000): Unknown query id: <query_id>

However, if you specify a user name, no error is issued for non-connected (or even non-existing) users. To check if the connection/query has been killed, you can use the ROW_COUNT() function.

A client whose connection is killed receives the following error:

ERROR 1317 (70100): Query execution was interrupted

To obtain a list of evisting sessions, use the SHOW PROCESSLIST statement or query the Information Schema PROCESSLIST table.

Note: You cannot use KILL with the Embedded MySQL Server library because the embedded server merely runs inside the threads of the host application. It does not create any connection threads of its own.

Note: You can also use mysqladmin kill thread_id [,thread_id...] to kill connections. To get a list of running queries, use mysqladmin processlist. See mysqladmin.

Comments

Comments loading...
Content reproduced on this site is the property of its respective owners, and this content is not reviewed in advance by MariaDB. The views, information and opinions expressed by this content do not necessarily represent those of MariaDB or any other party.