如何抑制单个 SQL 语句的列标题输出?

2021-11-20 00:00:00 output mysql columnheader suppression

我正在批量执行一些 SQL 语句(使用 mysql 命令行二进制文件).我希望我的几个 SELECT 语句之一不打印列标题,只打印选定的记录.这可能吗?

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?

推荐答案

使用 -N 调用 mysql(-N 的别名是 --skip-column-names) 选项:

Invoke mysql with the -N (the alias for -N is --skip-column-names) option:

mysql -N ...
use testdb;
select * from names;

+------+-------+
|    1 | pete  |
|    2 | john  |
|    3 | mike  |
+------+-------+
3 rows in set (0.00 sec)

感谢 ErichBSchulz 指出 -N 别名.

Credit to ErichBSchulz for pointing out the -N alias.

要移除结果周围的网格(垂直线和水平线),请使用 -s (--silent).列用 TAB 字符分隔.

To remove the grid (the vertical and horizontal lines) around the results use -s (--silent). Columns are separated with a TAB character.

mysql -s ...
use testdb;
select * from names;

id  name
1   pete
2   john
3   mike

要输出没有标题和网格的数据,只需同时使用 -s-N.

To output the data with no headers and no grid just use both -s and -N.

mysql -sN ...

相关文章