MySQL 如何抑制单个 SQL 语句的列标题输出?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/16101495/
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
How can I suppress column header output for a single SQL statement?
提问by einpoklum
I'm executing some SQL statements in batch (using the mysql
command-line binary). I want one of my several SELECT statements to not print the column headers, just the selected records. Is this possible?
我正在批量执行一些 SQL 语句(使用mysql
命令行二进制文件)。我希望我的几个 SELECT 语句之一不打印列标题,只打印选定的记录。这可能吗?
回答by suspectus
Invoke mysql with the -N
(the alias for -N
is --skip-column-names
) option:
使用-N
(别名为-N
is --skip-column-names
)选项调用 mysql :
mysql -N ...
use testdb;
select * from names;
+------+-------+
| 1 | pete |
| 2 | john |
| 3 | mike |
+------+-------+
3 rows in set (0.00 sec)
Credit to ErichBSchulz for pointing out the -N alias.
感谢 ErichBSchulz 指出 -N 别名。
To remove the grid (the vertical and horizontal lines) around the results use -s
(--silent
). Columns are separated with a TAB
character.
要移除结果周围的网格(垂直线和水平线),请使用-s
( --silent
)。列用TAB
字符分隔。
mysql -s ...
use testdb;
select * from names;
id name
1 pete
2 john
3 mike
To output the data with no headers and no grid just use both -s
and -N
.
要输出没有标题和网格的数据,只需同时使用-s
和-N
。
mysql -sN ...
回答by Tom Warfield
You can fake it like this:
你可以像这样伪造它:
-- with column headings
select column1, column2 from some_table;
-- without column headings
select column1 as '', column2 as '' from some_table;