patternsqlMajor
MySQL console: Ctrl+C driving me nuts
Viewed 0 times
drivingctrlmysqlconsolenuts
Problem
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 (
This issue has been reported at 2003, and bumped several times since.
Is there a way to:
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?
Solution
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:
Or, do like I did and create a MySQL config file for your user account at
This will ensure that all
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 DBNAMEOr, 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=TRUEThis will ensure that all
mysql executions ignore the annoying Ctrl-C and behave like a good SQL client.Code Snippets
mysql --host=127.0.0.1 --port=8900 --user=root -p --sigint-ignore DBNAME[mysql]
sigint-ignore=TRUEContext
StackExchange Database Administrators Q#20566, answer score: 29
Revisions (0)
No revisions yet.