Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MYSQL differs in Output from script

Tags:

linux

bash

mysql

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.

like image 746
Sriharsha Kalluru Avatar asked Dec 09 '12 19:12

Sriharsha Kalluru


1 Answers

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.
like image 71
Michael Berkowski Avatar answered Oct 02 '22 22:10

Michael Berkowski