Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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

share|improve this question

4 Answers 4

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

share|improve this answer
1  
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
    
Actually what I'd rather it did was exactly what psql does: if you are half way into entering a query, perhaps having entered several lines already, and you realize you have made a mistake and want to abort entering it, then pressing CTRL+C should clear back to the prompt. –  harmic Mar 10 at 23:09

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

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.

share|improve this answer

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.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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