SQL Keywords

SQL KILL

What is the SQL KILL statement?

Terminates a database session or currently running query by its identifier, instantly freeing server resources.
Sign up to get up to date news on SQL keywords
Welcome to the Galaxy, Guardian!
You'll be receiving a confirmation email

Follow us on twitter :)
Oops! Something went wrong while submitting the form.

Compatible dialects for SQL KILL: Supports: MySQL, MariaDB, SQL Server, Sybase ASE Not supported: PostgreSQL, Oracle, SQLite, Standard SQL

SQL KILL Full Explanation

KILL is an administrative statement used to abort an active connection (session) or the statement currently executing in that connection. It is available in MySQL/MariaDB and SQL Server (as well as Sybase ASE). When executed, the server sends a signal to the target process, rolls back any uncommitted work, and releases locks and memory. In MySQL you can choose to kill either the whole connection or only the query. In SQL Server you can monitor rollback progress with WITH STATUSONLY. Because KILL can disrupt work and cause rollback overhead, it is restricted to high-level privileges (CONNECTION_ADMIN or SUPER in MySQL, sysadmin or processadmin in SQL Server). KILL never affects the session issuing the command unless its own ID is specified. It is not part of the ANSI/ISO SQL standard and is unsupported in PostgreSQL, Oracle, or SQLite, which offer their own functions to terminate sessions.

SQL KILL Syntax

-- MySQL / MariaDB
KILL [CONNECTION | QUERY] thread_id;

-- SQL Server (T-SQL)
KILL session_id [WITH STATUSONLY];

SQL KILL Parameters

  • thread_id (integer) - MySQL: The value from SHOW PROCESSLIST.ID designating the thread to kill.
  • CONNECTION | QUERY (keyword) - MySQL: CONNECTION ends the session; QUERY stops only the current statement.
  • session_id (integer) - SQL Server: The session_id from sys.dm_exec_sessions to terminate.
  • WITH STATUSONLY (clause) - SQL Server: Returns estimated rollback progress without killing the session.
  • UOW (GUID) - SQL Server: Optional. Ends a specific distributed transaction by Unit of Work ID.

Example Queries Using SQL KILL

-- Find long-running sessions in MySQL
SHOW FULL PROCESSLIST;
KILL 52;  -- abort connection 52

-- Cancel only the statement but keep the connection
KILL QUERY 52;

-- In SQL Server, end a blocking session
SELECT session_id, wait_type, cpu_time FROM sys.dm_exec_sessions WHERE status = 'running';
KILL 75;  -- terminate session 75

Expected Output Using SQL KILL

  • The targeted session immediately receives an error (e
  • g
  • , "Error 1927: Connection was killed")
  • Any uncommitted transactions are rolled back
  • Other sessions waiting on locks held by the killed session are unblocked
  • The KILL statement itself returns OK (MySQL) or a completion message (SQL Server)

Use Cases with SQL KILL

  • Stop a runaway analytical query that consumes excessive CPU or memory.
  • Remove idle sessions holding locks that block DDL or maintenance work.
  • Terminate orphaned connections after an application crash.
  • Free resources quickly during an incident response to restore database performance.

Common Mistakes with SQL KILL

  • Killing the wrong session ID and disconnecting a legitimate user.
  • Expecting immediate resource release; large rollbacks can take time.
  • Lacking sufficient privileges and receiving an access denied error.
  • Attempting KILL in databases that do not support the statement (PostgreSQL, Oracle, SQLite).

Related Topics

SHOW PROCESSLIST, pg_terminate_backend, ALTER SYSTEM KILL SESSION, sys.dm_exec_sessions, ROLLBACK

First Introduced In

MySQL 3.23 (1999)

Frequently Asked Questions

What happens to uncommitted data when I run KILL?

The server automatically rolls back any uncommitted transactions belonging to the killed session to keep the database consistent.

Can I kill only the currently running query and keep the connection?

In MySQL use `KILL QUERY thread_id`. SQL Server does not distinguish; you must terminate the whole session.

How do I find the correct session ID to kill?

Use `SHOW PROCESSLIST` in MySQL or query `sys.dm_exec_sessions` in SQL Server to list active sessions and their IDs.

Is KILL logged or auditable?

Yes. Both MySQL and SQL Server record the kill action in the error log and/or system views, allowing administrators to audit who executed it.

Sign up to get up to date news on SQL keywords
Welcome to the Galaxy, Guardian!
You'll be receiving a confirmation email

Follow us on twitter :)
Oops! Something went wrong while submitting the form.
Trusted by top engineers on high-velocity teams
Aryeo Logo
Assort Health
Curri
Rubie Logo
Bauhealth Logo
Truvideo Logo

Check out other commonly used SQL Keywords!