简体   繁体   English

在Bash中解析MySQL输出

[英]Parsing MySQL output in Bash

How can I redirect output of mysql query with table border as separator? 如何将表边框的mysql查询输出重定向为分隔符? I try with this code : 我尝试使用此代码:

mysql -u root -h localhost -D cronjob -e "select * from cron_list" > query.txt

What I expect is output like : 我期望输出如下:

| id |  datetime  | recurrency |          command          |
|  1 | 2014-10-10 |    daily   | bash /media/data/daily.sh |
|  2 | 2014-10-09 |  minutely  |           conky           |

But when I use that code, it give me output like 但是,当我使用该代码时,它会给我输出

 id   datetime   recurrency           command          
  1  2014-10-10     daily    bash /media/data/daily.sh 
  2  2014-10-09   minutely             conky           

So, how can I redirect the output from terminal into file with separator like in terminal? 那么,如何将终端的输出重定向到带终端的分隔符的文件? Sorry for bad english 抱歉英文不好

From man mysql : 来自man mysql

--table, -t --table,-t

Display output in table format. 以表格格式显示输出。 This is the default for interactive use, but can be used to produce table output in batch mode. 这是交互式使用的默认设置,但可用于以批处理模式生成表输出。

Note -t is the default behaviour, but not whenever you pipe to a file. 注意-t是默认行为,但不管何时管道到文件。 That's why in that case you have to make it explicit. 这就是为什么在这种情况下你必须明确。


Other interesting options, for other kind of outputs: 其他有趣的选项,适用于其他类型的输出:

--silent, -s --silent,-s

Silent mode. 静音模式。 Produce less output. 产量减少。 This option can be given multiple times to produce less and less output. 可以多次给出此选项以产生越来越少的输出。

This option results in nontabular output format and escaping of special characters. 此选项会导致非常规输出格式和特殊字符的转义。 Escaping may be disabled by using raw mode; 可以使用原始模式禁用转义; see the description for the --raw option. 请参阅--raw选项的说明。

--skip-column-names , -N --skip-column-names ,-N

Do not write column names in results. 不要在结果中写入列名。

--html, -H --html,-H

Produce HTML output. 生成HTML输出。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM