When I do a SELECT in MySQL's command-line interpreter I get a sweet ASCII table:
+----+------+ | id | name | +----+------+ | 1 | Bob | | 2 | Mary | | 3 | Jane | | 4 | Lisa | +----+------+
However, if I pipe the result somewhere (e.g., echo "SELECT ..." | mysql
), I get a boring old tab-delimited result.
How can I get the fancy table format in stdout?
You can use the -t
or --table
switch on the mysql
command, e.g.
$ echo "SELECT ..." | mysql -t | cowsay -n
_______________
/ +----+------+ \
| | id | name | |
| +----+------+ |
| | 1 | Bob | |
| | 2 | Mary | |
| | 3 | Jane | |
| | 4 | Lisa | |
\ +----+------+ /
---------------
\ ^__^
\ (oo)\_______
(__)\ )\/\
||----w |
|| ||
Try this:
$ mysql -uyourUsername -pyourPassword -te 'SELECT * FROM aTable' aDatabase
+----+------+
| id | name |
+----+------+
| 1 | Bob |
| 2 | Mary |
| 3 | Jane |
| 4 | Lisa |
+----+------+
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With