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

2023-04-27数据库问题
2

本文介绍了如何抑制单个 SQL 语句的列标题输出?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

我正在批量执行一些 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 ...

这篇关于如何抑制单个 SQL 语句的列标题输出?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

The End

相关推荐

Mysql目录里的ibtmp1文件过大造成磁盘占满的解决办法
ibtmp1是非压缩的innodb临时表的独立表空间,通过innodb_temp_data_file_path参数指定文件的路径,文件名和大小,默认配置为ibtmp1:12M:autoextend,也就是说在文件系统磁盘足够的情况下,这个文件大小是可以无限增长的。 为了避免ibtmp1文件无止境的暴涨导致...
2025-01-02 数据库问题
151

SQL 子句“GROUP BY 1"是什么意思?意思是?
What does SQL clause quot;GROUP BY 1quot; mean?(SQL 子句“GROUP BY 1是什么意思?意思是?)...
2024-04-16 数据库问题
62

MySQL groupwise MAX() 返回意外结果
MySQL groupwise MAX() returns unexpected results(MySQL groupwise MAX() 返回意外结果)...
2024-04-16 数据库问题
13

MySQL SELECT 按组最频繁
MySQL SELECT most frequent by group(MySQL SELECT 按组最频繁)...
2024-04-16 数据库问题
16

为什么 Mysql 的 Group By 和 Oracle 的 Group by 行为不同
Why Mysql#39;s Group By and Oracle#39;s Group by behaviours are different(为什么 Mysql 的 Group By 和 Oracle 的 Group by 行为不同)...
2024-04-16 数据库问题
13

MySQL GROUP BY DateTime +/- 3 秒
MySQL GROUP BY DateTime +/- 3 seconds(MySQL GROUP BY DateTime +/- 3 秒)...
2024-04-16 数据库问题
14