I have a problem with the MySQL output formatting while executing the commands from a bash script.
If I execute a command on the command line then, I am able to get the output in formatted as expected.
$ mysql -u dbclient -pxxxx GEKONYLOGDB -e "select now(),max(time_stamp) from metrics"
+---------------------+---------------------+
| now()               | max(time_stamp)     |
+---------------------+---------------------+
| 2012-12-09 14:25:38 | 2012-12-09 14:25:20 |
+---------------------+---------------------+
But where as if I keep the same command in a script and execute I am not getting the formatted output.
$ cat test
#!/bin/bash
mysql -u dbclient -pxxxx GEKONYLOGDB -e "select now(),max(time_stamp) from metrics"
$ ./test
now()   max(time_stamp)
2012-12-09 14:27:52     2012-12-09 14:27:47 
So all I need the same output from script.
Thanks.
Pass the -t or --table option to force table output.
mysql --table -u dbclient -pxxxx GEKONYLOGDB -e "select now(),max(time_stamp) from metrics"
From mysql --help:
  -t, --table         Output in table format.
                        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