Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Why does MySQL print "\\." instead of "\." on the command line?

I just want to select backslash-period "(\.)".

In the MySQL client when I run

mysql> select '\\.';
+----+
| \. |
+----+

That is the outcome I want, but when I create a file name reverse.sql contains the same query as following

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

cat reverse.sql
select '\\';

When I run this query in the following way I get:

mysql -h mysqlhost -u admin -p -N mydatabase < reverse.sql

\\.

Instead of \. I get \\..

Because backslash-period is special character bash hinders me I guess, but is there any way to solve this issue and get "\." instead of "\\."?

MySQL version 8.0.37

Thanks!

>Solution :

% mysql -N < reverse.sql      
\\.

% mysql --raw -N < reverse.sql
\.

Cf. https://dev.mysql.com/doc/refman/8.0/en/mysql-command-options.html#option_mysql_raw

For nontabular output (such as is produced in batch mode or when the --batch or --silent option is given), special characters are escaped in the output so they can be identified easily. Newline, tab, NUL, and backslash are written as \n, \t, \0, and \\. The --raw option disables this character escaping.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading