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

时间:2022-10-21 20:54:41

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

与--disable-column-names选项一样,我们是否有选项来获取没有表格格式的sql查询?

example:

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

mysql -u username -ppassword --disable-column-names --execute“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

3 个解决方案

#1


68  

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, - block:以非表格输出格式打印结果。

--execute : Execute the statement and quit.

--execute:执行语句并退出。

HTH

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

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

#2


18  

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.

您可能还需要为-raw输出指定-r,这也会禁用字符转义,否则newline,tab,null char和反斜杠将分别表示为\ 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)
           \

- Oracle Corporation

- Oracle Corporation

MySQL 5.7 06/07/2018

MySQL 5.7 06/07/2018

#3


1  

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 username -ppassword --disable-column-names --execute“select name from test”> testFile

#1


68  

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, - block:以非表格输出格式打印结果。

--execute : Execute the statement and quit.

--execute:执行语句并退出。

HTH

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

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

#2


18  

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.

您可能还需要为-raw输出指定-r,这也会禁用字符转义,否则newline,tab,null char和反斜杠将分别表示为\ 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)
           \

- Oracle Corporation

- Oracle Corporation

MySQL 5.7 06/07/2018

MySQL 5.7 06/07/2018

#3


1  

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 username -ppassword --disable-column-names --execute“select name from test”> testFile