In the mysql
command line, pressing Control-C will cancel the programme, and bring you back to bash. In psql
, the one for postgres, it will kill the current query and will not stop the psql programme. Is there any way to get the psql style behaviour for Control-C in the mysql programme? I keep finding myself pressing Control-C by habit and having to log back into mysql.
Control C doesn't kill bash, and log you out when you press it. Which I think is a good thing. Control-C means 'stop what you're doing'.
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:
If you press Ctrl-C in 5.1 during query execution, it will halt the execution with the message "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).
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.