Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to stop a running mysql query

Tags:

How do I stop a running mysql query programmatically?

The problem I'm facing is that a query is constructed using user supplied data, and may occasionally take a very long time to execute (large tables 15 - 30 million rows). I want to offer the user a cancel-option, but don't know how to stop the currently executing mysql-query.

The application is a Java applet-servlet: the user specify criteria in the applet which is passed to the servlet where a handler-class is created to handle the request. This handler-class is self-contained re connect - query - disconnect to mysql.

Given this scenario, how do I cancel a running mysql-query?

like image 757
slashmais Avatar asked Jan 14 '10 15:01

slashmais


People also ask

How do you kill a query?

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.

How do you kill a running procedure in MySQL?

MySQL does not have a unique command for killing all processes. To kill all processes for a specific user, use CONCAT to create a file with the list of threads and statements. In our case, we entered root as the user. To specify another user, replace root with the desired username.

How do I kill a query in phpMyAdmin?

In phpMyAdmin, go to home page > Status; you'll see a list of your MySQL processes and you have a Kill link for each of them.


1 Answers

SHOW PROCESSLIST; KILL <thread_to_be_killed>; 

Refer to the documentation for additional details

Show The Process List

Kill A Running Thread

like image 165
George Johnston Avatar answered Oct 05 '22 00:10

George Johnston