Take the 2-minute tour ×
Database Administrators Stack Exchange is a question and answer site for database professionals who wish to improve their database skills and learn from others in the community. It's 100% free, no registration required.

There is something in the MySQL console that drives me nuts. When I hit ctrl+c to cancel the current command being typed, the terminal exits.

In every terminal I know (*nix terminals, Python, PostgreSQL), ctrl+c cancels the current command and ctrl+d exits the terminal.

This issue has been reported at 2003, and bumped several times since.

Is there a way to:

  • Change this behaviour, or
  • Convince the MySQL dev team that this is really annoying?
share|improve this question

4 Answers 4

up vote 3 down vote accepted

To change the behaviour, download the source for the mysql CLI and modify the SIGINT handler to behave as you see fit, then recompile & install.

share|improve this answer
    
Isn't this potentially dangerous? There's no guarantee that it would work for future versions. Plus, it looks like it'd work, but how would you know that you wouldn't get some weird behavior at a totally unrelated place later? –  Pacerier Jan 10 at 14:19

While the ctrl+c behavior is annoying, you can still use \c to cancel the current query. You just have to train yourself that when using mysql CLI, you use \c instead of ctrl+c!

share|improve this answer
    
Who is the guy that came up with this idea? We want his head. –  Pacerier Jan 10 at 14:21

At least version 5.6.14 of the client has the --sigint-ignore option to totally ignore the SIGINT handler. It appears to have been added on Oct 7th, 2004 -- so it's been around a while at least. I just tested it, and it does keep CTRL-C from cancelling the MySQL client. However, it would be nice if CTRL-C would also cancel the current command line buffer like it does on the BASH shell -- as the PostgreSQL CLI does. I've forked MySQL in order to see how hard it would be to implement some such thing. I'll post a Homebrew formula with a tarball link when/if it's ready.

UPDATE 1 Ever have one of those days? I created the promised patch, and then I decided to create a video to demonstrate it. It worked! However, I couldn't disable it! Well, it turns out that MySQL actually baked in the functionality to the core client last year! Yep, the A to this Q is to download at least MySQL 5.7.3-794-g901d27f's client. It has the functionality we all desired.

EXAMPLE From the command line just add the --sigint-ignore flag:

mysql --host=127.0.0.1 --port=8900 --user=root -p --sigint-ignore DBNAME

Or, do like I did and create a MySQL config file for your user account at $HOME/.my.cnf (%USERPROFILE%/.my.cnf on Windows) with the following content:

[mysql]
sigint-ignore=TRUE

This will ensure that all mysql executions ignore the annoying Ctrl-C and behave like a good SQL client.

share|improve this answer
    
Ever have one of those days? I created the promised patch, and then I decided to create a video to demonstrate it. It worked! However, I couldn't disable it! Well, it turns out that MySQL actually baked in the functionality to the core client last year! Yep, the A to this Q is to download at least MySQL 5.7.3-794-g901d27f's client. It has the functionality we all desired. –  user2598329 Apr 30 at 20:56
1  
you should "edit" your answer to include that info instead of posting it as a comment. –  Max Vernon Apr 30 at 21:49
    
Getting an answer three years later is impressive. Please incorporate your comment in your answer (and please add a command-line code example) so I can accept it. –  Adam Matan May 1 at 8:57
    
Hi Max, I would have, but I don't have the karma to include more than two links in a single comment. –  user2598329 May 1 at 21:56
    
I've updated my answer per requested. –  user2598329 May 2 at 15:02

What version of the client are you using? I remember this being the older behavior but recent versions of 5.1 and 5.5 seem to just cancel the running command without exiting the client. Then again it may be that I'm using the Percona builds. You could try just running their client if that's the case.

share|improve this answer
    
hmm, I'm running 5.5 Percona and ctrl+c still aborts the mysql client (not the current sql command) –  Derek Downey Jul 9 '12 at 15:19
    
I think I misread the OP. My response was addressing a command that was in the middle of being executed, not the desire to blank you a yet to be run command. –  atxdba Jul 9 '12 at 15:23
    
I concur with @atxdba - I'm also running the Percona build of 5.5, and ctrl+c drops out of the currently executing command. If there is no command executing, it drops out of the CLI. It may be that ctrl+d drops out of a shell that is running, but if you have a script running within the shell, that will stop if you hit ctrl+c... different commands for different apps / shells / scripts! Can be confusing... :~s –  Dave Rix Jul 9 '12 at 15:38
    
@DaveRix I agree too, ctrl+c drops out of a query that's currently executing. But that's not what the OP was about unfortunately. –  Derek Downey Jul 10 '12 at 13:55

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.