This is not, strictly speaking, a bug. TEE and PAGER commands don't work in the batch mode, this is intentional and documented (e.g see mysql --help). And batch mode is enabled whenever the input is not the terminal.
I'd rather say that MySQL-5.6 behavior is a bug. There was a crash when TEE was used in embedded server. It's Bug#11764633, fixed in commit d608ad2dd6. Later they've removed the check for the batch mode from the TEE command (in commit 47f7fc4353) to be able to test the fix for Bug#11764633 in the test suite. Usually debugging changes like that are only enabled in a special "testing" mode, but Oracle has unintentionally enabled TEE in batch mode for everyone. I say "unintentionally" because the help text wasn't changed and the --tee command line option still doesn't work in batch mode, so it apparently was not an intentional decision "let's enable TEE in batch mode".
Anyway, I tend to agree that this "buggy" 5.6 behavior is more practically useful than the old intentional behavior of mysql client. We can enable TEE in the batch mode.
That includes
- enable TEE and PAGER in the batch mode
- enable --tee and --pager in the batch mode
- update the help text accordingly
Related useful change:
- make it possible to disable batch mode from the command line
Alternatively, we can do just the last item (make it possible to disable batch mode) and whoever needs TEE or PAGER will have to disable batch mode to use them.
As a workaround you can use tee after the mysql client:
echo "SHOW MASTER STATUS\G" | mysql | tee /tmp/foo
Reproducible on MySQL 5.5, apparently fixed in 5.6.
Assigned to Alexander Barkov, because here is the only commit I found in 5.6 that mentions TEE – of course, it doesn't necessarily mean it's the one, but it's a viable suspect.
revno: 2876.368.113 revision-id: alexander.barkov@oracle.com-20110223045307-u316hqua4z5j86xe parent: andrei.elkin@oracle.com-20110222155247-k07c3725arfph223 committer: Alexander Barkov <alexander.barkov@oracle.com> branch nick: mysql-trunk.w5331 timestamp: Wed 2011-02-23 07:53:07 +0300 message: WL#5331 Support Unicode for Windows command line client Based on the original patch form Vladislav Vaintroub: http://lists.mysql.com/commits/105379 @ client/mysql.cc - introducing new function tee_write(), to reuse in a number of places where similar loops displaying data occurs. - introducing flags for tee_write(), to support different printing modes, according to --xml, --raw, --tab, etc, parameters - Instead if using argv (which is always in ANSI code page), we now use UTF16LE API to access command line arguments on Windows, using this scenario: a. We translate arguments to UTF8MB4 on startup. b. Then we process arguments and detect connection character set from --default-character-set arguments (or my.ini value), or from the OS localization information by default. c. Then we convert user, database and the --execute (-e) buffer from UTF8MB4 to the connection character set. d. Connect - Instead of printing using printif/fputs family functions on Windows, which are limited to the current DOS code page (cp850 on a Western machine) we now use UTF16LE console API through the new my_win_console_xxx() functions implemented in my_conio.c - Using mysql_set_character_set() instead of mysql_option(OPT_CHARACTER_SET_NAME) to know the ongoing session character set *before* mysql_real_connect() call, to convert user and database properly. - my_win_is_console_cached() has been added to cache my_win_is_console() result for stdout and stderr, for performance purposes. ...