mysql命令行到垂直输出

fre*_*nus 7 mysql command-line

我想得到一个带有垂直输出的mysql查询的结果.使用--vertical(或G)时我遇到的问题是星号线.

    $mysql -N -e 'select filed1, field2 from db.tlb\G'
    *************************** 1. row ***************************
    value1_field1
    value1_field2
    *************************** 2. row ***************************
    value2_field1
    value2_field2
    ...
Run Code Online (Sandbox Code Playgroud)

是否有一个选项我没有找到摆脱***[...] x行.排[...]***?

目前,我正在使用egrep -v'^\*.*\*$',但我确信存在更好的解决方案.

Syl*_*oux 0

我不确定这是一个好的解决方案,但如果显式使用egrep很烦人,您可以定义一个 shell 函数来mysql使用所需的pager启动。假设您使用的是bash(或兼容的):

# define a shell function to launch mysql with the required _pager_
sh$ mysql() { `which mysql` $* --pager="egrep -v '^\*.*\*$'" ; }

[ ... ]

# launch mysql "as usual" (in reality, this is the shell function that is invoked)
sh$ mysql -u user -p -h mysql-host mydb
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 67
Server version: 5.1.49-3 (Debian)

-- Use mysql normally -- but the "egrep pager" will remove the "star lines"
mysql> select * from T\G
col1: w
col2: x
col3: 0.4
1 row in set (0.00 sec)
Run Code Online (Sandbox Code Playgroud)

正如我之前所说,这不是一个完美的解决方案,因为egrep会盲目地从输出中删除任何“星线”——而不仅仅是来自ego ( \G) 命令的星线。