MySQL 获取不带表格式的sql查询结果
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/16711598/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Get the sql query result without the table format
提问by John
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
回答by Harsh Gupta
Add -B
option to mysql
.
将-B
选项添加到mysql
.
mysql -B -u username -ppassword \
--disable-column-names \
--execute "select name from mydb.test"
-B, --batch: Print results in nontabular output format.
-B, --batch:以非表格输出格式打印结果。
--execute: Execute the statement and quit.
--execute: 执行语句并退出。
HTH
HTH
Edit: Thanks to @ joescii, -B
, which is short for --batch
, also enables the --silent
switch.
编辑:感谢@joescii,-B
它是 的缩写--batch
,也启用了--silent
开关。
回答by Riot
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
为--raw
输出,即禁用字符转义为好,否则换行符,制表符,零炭和反斜杠将分别被表示为\ N,\吨,\ 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,
, 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) \· --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, ##代码##, 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
MySQL 5.7 06/07/2018
##代码##- 甲骨文公司
MySQL 5.7 06/07/2018