MYSQL的输出与脚本不同 [英] MYSQL differs in Output from script
本文介绍了MYSQL的输出与脚本不同的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在执行来自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.
谢谢.
推荐答案
传递-t
或--table
选项以强制表输出.
Pass the -t
or --table
option to force table output.
mysql --table -u dbclient -pxxxx GEKONYLOGDB -e "select now(),max(time_stamp) from metrics"
来自mysql --help
:
-t, --table Output in table format.
这篇关于MYSQL的输出与脚本不同的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文