Bug #66583 Ctrl-C behavior violates principle of least astonishment
Submitted: 28 Aug 2012 20:54 Modified: 10 Dec 2012 17:40
Reporter: Chris Cowart Email Updates:
Status: Closed Impact on me:
Category:MySQL Server: Command-line Clients Severity:S4 (Feature request)
Version:Ver 14.12 Distrib 5.0.60, for redhat-lin OS:Any
Assigned to: CPU Architecture:Any
Triage: Needs Triage: D5 (Feature request)

[28 Aug 2012 20:54] Chris Cowart
This request was first raised in #1989, but what was implemented fell short of the original request. Despite community comments on that bug requesting it be reopened, it was not.

The expected behavior in a Unix world is that Ctrl-C will not terminate interactive programs. 

Editors (vim, emacs, nano), MUAs (alpine, mutt), Shells (bash, zsh, csh, tcsh, sh, ksh), and other DB clients (psql) all catch SIGINT to cancel the current operation. If no operation is in progress, the SIGINT is discarded (possibly with instructions to the user on how to exit if that's what they want).

No user with a unix background expects an interactive program to exit on a Ctrl-C. I would wager a bet that every year, thousands of hours are wasted when mysql client users hit Ctrl-C to cancel what they're typing, to cancel a long-running query that finishes before the SIGINT is handled, or just pound on Ctrl-C out of habit -- only to have to switch to their Keychain or Keepass, retype their login credentials, reconnect, etc. Just google around for all the people complaining that this is broken and observe the complete lack of a satisfactory resolution.

This is a serious useability flaw. People expect Ctrl-C to behave one way given a long history of experience with other command line tools. They waste a great deal of time trying in vein to teach themselves that mysql is the one exception.

How to repeat:
Use the mysql client (without --sigint-ignore). Type Ctrl-C.

Suggested fix:
--sigint-ignore isn't the right approach. It doesn't allow you to cancel long-running queries or to get a fresh mysql prompt.

The request is to behave like a shell:

% mysql -D test
mysql> SELECT foo, ^C
mysql> SELECT * FROM really_really_big_table;
mysql> ^D

It's fine if this behavior has to be configured. But it needs to be available.
[29 Aug 2012 6:26] Valeriy Kravchuk
That bug you refer to is fixed in 5.1, 5.0.x is no longer actively supported. On modern version I see exactly the fix as described and intended:

[openxs@chief 5.6]$ bin/mysql -uroot test
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.6.7-debug Source distribution

Copyright (c) 2000, 2012, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> select sleep(20);
^CCtrl-C -- sending "KILL QUERY 1" to server ...
Ctrl-C -- query aborted.
| sleep(20) |
1 row in set (1.18 sec)

mysql> select version();
| version()   |
| 5.6.7-debug |
1 row in set (0.00 sec)

mysql> select sleep(20);
^CCtrl-C -- sending "KILL QUERY 1" to server ...
Ctrl-C -- query aborted.
| sleep(20) |
1 row in set (0.89 sec)

mysql> Ctrl-C -- exit!

So, Ctrl-C kills current query, if pressed twice or there is no current query then mysql client is aborted. Isn't this enough for most use cases?
[29 Aug 2012 7:11] Chris Cowart
No, the whole point is that no matter how many times you press Ctrl-C, the mysql client should not exit.

The precedent among all other interactive unix programs is that Ctrl-C will abort the current operation, abort what you've typed, or if neither is applIcable, behave as a no-op. 

Ctrl-D (as eof, signalling no more input) often exits interactive programs (all the shells I referenced in the original report and the psql client). Ctrl-C does not cause any of the programs I mentioned to exit, no matter how many times you press it.

The behavior is astonishing and frustrating to users who are used to widely accept behavior of interactive CLI tools. I'm not saying it had to be the default (though I think it should be), but it at least needs to be configurable. Google around for "MySQL Ctrl-c" and see how many people are astonished and frustrated by the exit-on-sigint behavior.
[29 Aug 2012 8:36] Valeriy Kravchuk
OK, I've got your point.
[10 Dec 2012 17:40] Paul Dubois
Noted in 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.