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?

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.

| improve this answer | |
  • 2
    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 '15 at 14:19

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= --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:


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

| improve this answer | |

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!

| improve this answer | |
  • 2
    Who is the guy that came up with this idea? We want his head. – Pacerier Jan 10 '15 at 14:21
  • 2
    You can also use Ctrl+U to delete to the start of the line, and Ctrl+W to delete one word backward. – Damien Ó Ceallaigh Nov 2 '16 at 4:13

Good news: MySQL's ^C functionality has finally been fixed by #66583.

From the 5.7.0 changelog:

Previously, Control+C in mysql interrupted the current statement if there was one, or exited mysql if not. Now Control+C interrupts the current statement if there was one, or cancels any partial input line otherwise, but does not exit.

| improve this answer | |
  • I'm using 5.6.35 and verified this is not an issue. – flow2k Sep 25 '17 at 18:49

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.

| 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

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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