1

On my machine the command mysql -e "show databases" generates the following output:

$ mysql -e "show databases

+--------------------+
| Database           |
+--------------------+
| information_schema |
| database1          |
| database2          |
| mysql              |
| performance_schema |
| sys                |
+--------------------+

However, when I pipe this to any command (or redirect to file), the formatting vanishes:

$ mysql -e "show databases" | cat

Database
information_schema
database1
database2
mysql
performance_schema
sys

I thought that the formatting may come through stderr, but this does not seem to be the case:

$ mysql -e "show databases" 2>/dev/null

+--------------------+
| Database           |
+--------------------+
| information_schema |
| database1          |
| database2          |
| mysql              |
| performance_schema |
| sys                |
+--------------------+

Why do the formatting characters not go through the pipe? Can I change this behaviour?

Flourid
  • 113
  • 2

1 Answers1

4

MySQL changes output [format] when the pipe changes from stdout to another application.

To preserve this format use the --table option or use --tabbed or --vertical.

Artem S. Tashkinov
  • 26,392
  • 4
  • 33
  • 64