I am executing a Command
mysql -uroot -proot -Bse "select Concat('SHOW CREATE TABLE ',TABLE_SCHEMA ,'.',TABLE_NAME,'\\G') from information_schema.tables where TABLE_SCHEMA Not IN('mysql','information_schema','performance_schema');"
I want output as
SHOW CREATE TABLE sakila.category\G
SHOW CREATE TABLE sakila.city\G
SHOW CREATE TABLE sakila.country\G
SHOW CREATE TABLE sakila.customer\G
But I am getting
SHOW CREATE TABLE sakila.categoryG
SHOW CREATE TABLE sakila.cityG
SHOW CREATE TABLE sakila.countryG
SHOW CREATE TABLE sakila.customerG
Why is this so? Where am I wrong?
UPDATE
If I write
mysql -uroot -proot -Bse "select Concat('SHOW CREATE TABLE ',TABLE_SCHEMA ,'.',TABLE_NAME,'\\\\G') from information_schema.tables where TABLE_SCHEMA Not IN('mysql','information_schema','performance_schema');"
I get output as
SHOW CREATE TABLE sakila.category\\G
SHOW CREATE TABLE sakila.city\\G
SHOW CREATE TABLE sakila.country\\G
SHOW CREATE TABLE sakila.customer\\G
But I only want \G, not \\G.
You need an additional level of escaping:
\\\\You give the query string th MySQL via a shell command line. The shell turns the
\\\\(\\twice) into two\, i. e.\\. That is because it is enclosed in"s.MySQL sees the
\\\\as\\and, as it has its own escaping, uses it as\.EDIT: I don’t understand why, but this doesn’t work with your query.
But by fiddling around with it, one wasily finds out that both
\\\\Gand\\\Gwould be the way to go.Alas, the data is modified on output in the MySQL CLI client. As its output is escaped to allow for
\0.\tetc. to be output, it as well has to escape the\on output.With the CLI parameter
-ror--raw, you can disable that behaviour. (Yoursoption, however, should be redundant, as it is included inB.) And maybeNwouldbe useful, disabling the headers.So use
-Breor-NBreinstead of-Bseand you are perfectly fine with\\\\G.