MySQL console: Ctrl+C driving me nuts
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.
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!
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.