Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I stop a running MySQL query?

I connect to mysql from my Linux shell. Every now and then I run a SELECT query that is too big. It prints and prints and I already know this is not what I meant. I would like to stop the query.

Hitting Ctrl+C (a couple of times) kills mysql completely and takes me back to shell, so I have to reconnect.

Is it possible to stop a query without killing mysql itself?

like image 379
David B Avatar asked Sep 24 '10 13:09

David B


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 process 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.


2 Answers

mysql>show processlist;  mysql> kill "number from first col"; 
like image 177
baklarz2048 Avatar answered Sep 22 '22 22:09

baklarz2048


Just to add

KILL QUERY **Id** where Id is connection id from show processlist

is more preferable if you are do not want to kill the connection usually when running from some application.

For more details you can read mysql doc here

like image 43
maaz Avatar answered Sep 26 '22 22:09

maaz