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

link|improve this question

79% accept rate
feedback

3 Answers

up vote 7 down vote accepted

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

link|improve this answer
It still has pretty stupid behaviour. When you press CTRL+C during a query, it should cancel the query. When you press CTRL+C at the prompt, it should do nothing and NOT exit MySQL. When you CTRL+C at the Bash prompt when nothing is happening, it does prints a new line, but basically does nothing. – Neil Feb 11 '10 at 15:43
feedback

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).
link|improve this answer
feedback

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.

link|improve this answer
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.