获取不包含表格格式的 SQL 查询结果

--disable-column-names选项一样,我们是否有一个不使用表格格式的 SQL 查询选项? 例如:

mysql -u username -p password  --disable-column-names --execute "select name from test"

结果如下:

-----
| A |
| B |
| C |
| D |
-----

是否可以使用下面的一些 sql 程序选项修饰符 没有表格格式来获得查询结果?

我要这个:

A
B
C
D
63505 次浏览

-B标志添加到 mysql

mysql -B -u username -ppassword \
--disable-column-names \
--execute "select name from mydb.test"
-B, --batch: Print results in nontabular output format.


--execute: Execute the statement and quit.

请注意,-B/--batch也支持 --silent开关。

虽然其他答案顺便工作,正确的开关实际上是 -s,这是简称 --silent

您可能需要为 --raw输出额外指定 -r,这也禁用字符转义,否则换行符、制表符、空字符和反斜杠将分别表示为 n、 t、0和。

   ·   --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, -r


For tabular output, the “boxing” around columns enables one column
value to be distinguished from another. For nontabular output (such
as is produced in batch mode or when the --batch or --silent option
is given), special characters are escaped in the output so they can
be identified easily. Newline, tab, NUL, and backslash are written
as \n, \t, \0, and \\. The --raw option disables this character
escaping.


The following example demonstrates tabular versus nontabular output
and the use of raw mode to disable escaping:


% mysql
mysql> SELECT CHAR(92);
+----------+
| CHAR(92) |
+----------+
| \        |
+----------+
% mysql -s
mysql> SELECT CHAR(92);
CHAR(92)
\\
% mysql -s -r
mysql> SELECT CHAR(92);
CHAR(92)
\

甲骨文公司

MySQL 5.706/07/2018