8

垂直出力で 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
    ...

行 ***[...] x を取り除くために私が見つけられなかったオプションはありますか? 行 [...]*** ?

現時点では、egrep -v '^\*.*\*$'を使用していますが、より良い解決策が存在すると確信しています。

4

3 に答える 3

0

これが良い解決策かどうかはわかりませんが、明示的に使用するのが面倒な場合は、目的のpageregrepで起動するシェル関数を定義できます。bash (または互換)を使用していると仮定します。mysql

# 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)

前に言ったように、これは完全な解決策ではありません。なぜなら、 ego ( ) コマンドegrepからのものだけでなく、出力から「スターライン」をやみくもに削除するからです。\G

于 2013-06-27T07:47:00.040 に答える
0

これを試してください(しかし、なぜそのような出力が必要なのか想像できません)

mysql -N -B -e 'select * from db' mysql | tr "\t" "\n"
于 2014-11-11T18:05:03.673 に答える