Sriharsha Kalluru
Sriharsha Kalluru

Reputation: 1823

MYSQL differs in Output from script

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.

Upvotes: 6

Views: 2246

Answers (2)

Robert Lujo
Robert Lujo

Reputation: 16371

If you want to have --table option enabled by default when calling mysql program, please check this SO answer How to store MySQL results to a file in table format.

Upvotes: 0

Michael Berkowski
Michael Berkowski

Reputation: 270637

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.

Upvotes: 13

Related Questions