Bug #35122 Escape characters printed in output when using client in silent mode
Submitted: 6 Mar 2008 16:40 Modified: 22 Apr 2008 17:28
Reporter: Gregory Haase Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server: Documentation Severity:S3 (Non-critical)
Version:5.0.45, 5.0.56 OS:Linux
Assigned to: Paul DuBois CPU Architecture:Any
Tags: backslash, batch, raw, silent

[6 Mar 2008 16:40] Gregory Haase
Description:
When running in silent mode, if you escape a special character both the special character and the escape string are output.

I discovered while I was attempting to select some data out of the information schema to paste into a mysqldump script.

In this particular case, I want to output the backslash character for a multi-line bash statement. When in normal mode, one backslash is output. However in order to use this output I need to strip the preceding pipe characters and all the trailing characters from each row.

Technically, silent mode strips all this out so the output can be pasted into the script, but in this case I noted that the backslash is output twice.

How to repeat:
[greg@localhost.localdomain ~]$ mysql -uroot -p

mysql> select concat('--ignore-table=',table_schema,'.',table_name,' \\') from information_schema.tables where table_schema = 'information_schema' and table_name like 'table%';
+-------------------------------------------------------------+
| concat('--ignore-table=',table_schema,'.',table_name,' \\') |
+-------------------------------------------------------------+
| --ignore-table=information_schema.TABLES \                  | 
| --ignore-table=information_schema.TABLE_CONSTRAINTS \       | 
| --ignore-table=information_schema.TABLE_PRIVILEGES \        | 
+-------------------------------------------------------------+

[greg@localhost.localdomain ~]$ mysql -uroot -p -s 
 
mysql> select concat('--ignore-table=',table_schema,'.',table_name,' \\') from information_schema.tables where table_schema = 'information_schema' and table_name like 'table%';
concat('--ignore-table=',table_schema,'.',table_name,' \\')
--ignore-table=information_schema.TABLES \\
--ignore-table=information_schema.TABLE_CONSTRAINTS \\
--ignore-table=information_schema.TABLE_PRIVILEGES \\
[6 Mar 2008 20:11] Valeriy Kravchuk
Thank you for a bug report. I have much simpler test case:

C:\Program Files\MySQL\MySQL Server 5.0\bin>mysql -uroot -proot -P3308 test
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 7
Server version: 5.0.56-enterprise-gpl-nt MySQL Enterprise Server (GPL)

Type 'help;' or '\h' for help. Type '\c' to clear the buffer.

mysql> select '\\';
+---+
| \ |
+---+
| \ |
+---+
1 row in set (0.00 sec)

mysql> exit
Bye

C:\Program Files\MySQL\MySQL Server 5.0\bin>mysql -uroot -proot -s -P3308 test
mysql> select '\\';
\
\\
mysql>

If the above is intended behaviour of -s mode, it should be documented at http://dev.mysql.com/doc/refman/5.0/en/mysql-command-options.html#option_mysql_silent
[25 Mar 2008 20:47] Chad MILLER
I think this isn't a bug.  Unescaped output is delimited by the table-layout bracketing, but in switching to silent, you lose borders and data/metadata identity unless its data is interpreted and represented as a logical chunk.  Newlines, tabs, NULs, and backslash all are interpreted and escaped, so a reader can know what is what in the output.

The correct solution is to add --raw or -r to the command line, which tells the client not to interpret and escape special characters.

The documentation should get an additional note that "silent" is like "batch" in that it may often be used with "raw".
[22 Apr 2008 14:05] Paul DuBois
Appears to be a documentation bug. Categorizing that way and assigning to myself.
[22 Apr 2008 17:28] Paul DuBois
Thank you for your bug report. This issue has been addressed in the documentation. The updated documentation will appear on our website shortly, and will be included in the next release of the relevant products.

Updated the descriptions for the --silent, --raw, and --batch options.
Gave example of various output formats in --raw option description.