Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I Interrupt a long query in the mysql command line tool without quitting mysql?

While debugging SQL statements, if I accidentally execute a query in using the mysql command line that outputs at lot of results (even if the query itself executes in reasonable time), the only way I know of to stop the endless stream of output is CTRL-C.

Unfortunately this puts me back in the shell, forcing me to login and select the database again.

To avoid this I've started running mysql with the --sigint-ignore option so that CTRL-C is ignored.

Now I'd like a way to interrupt the output of those long queries.

Is there a keyboard shortcut that will do this?

like image 505
rwired Avatar asked Jan 31 '09 05:01

rwired


People also ask

How do you kill a long running query in MySQL?

Run the following command: mysql> SELECT GROUP_CONCAT(CONCAT('KILL ',id,';') SEPARATOR ' ') FROM information_schema. processlist WHERE user <> 'system user'; This will kill all your MySQL queries.

How do I stop a MySQL command?

Suppose you're typing a command line query into a MySQL database and you need to cancel out and start over. From a bash shell you could just type ctrl-c and get a new prompt. In MySQL, ctrl-c would exit the client and return you to the shell.

How do you kill a long running query in SQL Server?

You can use the KILL SPID command to kill a particular user session. You can only KILL the user processes. Once we kill a session, it undergoes through the rollback process, and it might take time and resources as well to perform a rollback.


1 Answers

Not a keyboard shortcut.

The only choice is to open another session, use SHOW PROCESSLIST and then KILL QUERY the one you want to terminate.

You can also use the mysqladmin command-line tool to issue these commands.

Either way, it requires you to login. So it's not much of an advantage over just hitting Ctrl-C.

like image 62
Bill Karwin Avatar answered Sep 30 '22 03:09

Bill Karwin