获取带有out表格式的sql查询结果

时间:2021-12-17 23:29:28

Like --disable-column-names option, do we have a option to get the sql query without table format.

例如——disable-column-names选项,我们是否有一个选项可以获得没有表格式的sql查询。

example:

例子:

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

mysql -u用户名-ppassword -disable-column-name -执行“select name from test”

results below:

结果如下:

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

IS it possible to get the query result using some sql program option modifiers as below, [ without the table format ]

是否可以使用以下的sql程序选项修饰符获取查询结果(没有表格式)

A
B
C
D

Thanks in advance

谢谢提前

3 个解决方案

#1


61  

Add -B option to mysql.

向mysql添加-B选项。

mysql -B -u username -ppassword \
      --disable-column-names \
      --execute "select name from mydb.test"

-B, --batch : Print results in nontabular output format.

-B, -批量:打印结果为非表格输出格式。

--execute : Execute the statement and quit.

——执行:执行语句并退出。

HTH

HTH

Edit: Thanks to @ joescii, -B, which is short for --batch, also enables the --silent switch.

编辑:感谢@ joescii, -B,它是-batch的缩写,也支持-silent开关。

#2


17  

Although the other answers work incidentally, the correct switch is actually -s which is short for --silent.

虽然其他答案也可以,但正确的开关实际上是-s,也就是-silent。

You may want to additionally specify -r for --raw output, which disables character escaping as well, otherwise newline, tab, null char and backslash will be represented as \n, \t, \0 and \ respectively.

您可能还想为原始输出指定-r,它也禁用字符转义,否则,换行符、制表符、空字符和反斜杠将分别表示为\n、\t、\0和\。

#3


2  

It's possible to pipe the output to a file, without the the border frame.

在没有边框的情况下,可以将输出传输到文件。

mysql -u username -ppassword --disable-column-names --execute "select name from test" > testFile

mysql -u用户名-ppassword -disable-column-names -执行“select name from test”> testFile

#1


61  

Add -B option to mysql.

向mysql添加-B选项。

mysql -B -u username -ppassword \
      --disable-column-names \
      --execute "select name from mydb.test"

-B, --batch : Print results in nontabular output format.

-B, -批量:打印结果为非表格输出格式。

--execute : Execute the statement and quit.

——执行:执行语句并退出。

HTH

HTH

Edit: Thanks to @ joescii, -B, which is short for --batch, also enables the --silent switch.

编辑:感谢@ joescii, -B,它是-batch的缩写,也支持-silent开关。

#2


17  

Although the other answers work incidentally, the correct switch is actually -s which is short for --silent.

虽然其他答案也可以,但正确的开关实际上是-s,也就是-silent。

You may want to additionally specify -r for --raw output, which disables character escaping as well, otherwise newline, tab, null char and backslash will be represented as \n, \t, \0 and \ respectively.

您可能还想为原始输出指定-r,它也禁用字符转义,否则,换行符、制表符、空字符和反斜杠将分别表示为\n、\t、\0和\。

#3


2  

It's possible to pipe the output to a file, without the the border frame.

在没有边框的情况下,可以将输出传输到文件。

mysql -u username -ppassword --disable-column-names --execute "select name from test" > testFile

mysql -u用户名-ppassword -disable-column-names -执行“select name from test”> testFile