Fix Control-C in mysql command line programme?

If you press Ctrl-C in 5.1 during query execution, it will halt the execution with the message "Query execution was interrupted"

    mysql> INSERT INTO c SELECT rand()*1000, sha1(rand()) FROM c;
    Query aborted BY Ctrl+C
    ERROR 1317 (70100): Query execution was interrupted

A further Ctrl-C press kills the client.

Older versions die horribly as noted in question, so upgrade if possible :)

Edit:

Looks like it was added in 5.0.25 (and 5.1.10).


Like Andy says, it's fixed in later versions.

There's no equivalent keyboard shortcut in older versions.

But you can prevent it from happening with the following CLI flag:

--sigint-ignore

Ignore SIGINT signals (typically the result of typing Control-C).

If you add a \c to then end of your line instead of using Ctrl-c then you can kill the line without exiting mysql.


Short answer: As of early 2014 there is no way to have the described behaviour in mysql. See relevant bug report and a page in dba.stackexchange where 3 different people comment that it's still not fixed in v5.5. Also as far as I can tell after a long googling there is no workaround worth using (see bellow why --sigint-ignore is not good). Andy's answer was edited to mention that "Looks like it was added in 5.0.25 (and 5.1.10)." but he was probably misled by comment with date [3 May 2006 19:04] in the aforementioned bug report.

The --sigint-ignore argument (see Dan Carley's answer) will indeed stop mysql from dropping you back to the shell when you hit ctrl-C but will also remove the ability to stop long running queries.

This is the kind of usability bugs that makes you go :-( Really obvious and probably extremely easy to fix but still here it is after many years.