Skip to Main Content
MySQL Cookbook
book

MySQL Cookbook

by Paul DuBois
October 2002
Intermediate to advanced content levelIntermediate to advanced
1024 pages
27h 26m
English
O'Reilly Media, Inc.
Content preview from MySQL Cookbook

Suppressing Column Headings in Query Output

Problem

You don’t want to include column headings in query output.

Solution

Turn column headings off with the appropriate command-line option. Normally this is -N or --skip-column-names, but you can use -ss instead.

Discussion

Tab-delimited format is convenient for generating datafiles that you can import into other programs. However, the first row of output for each query lists the column headings by default, which may not always be what you want. Suppose you have a program named summarize the produces various descriptive statistics for a column of numbers. If you’re producing output from mysql to be used with this program, you wouldn’t want the header row because it would throw off the results. That is, if you ran a command like this, the output would be inaccurate because summarize would count the column heading:

% mysql -e "SELECT arms FROM limbs" cookbook | summarize

To create output that contains only data values, suppress the column header row with the -N (or --skip-column-names) option:

% mysql -N -e "SELECT arms FROM limbs" cookbook | summarize

-N and --skip-column-names were introduced in MySQL 3.22.20. For older versions, you can achieve the same effect by specifying the “silent” option (-s or --silent) twice:

% mysql -ss -e "SELECT arms FROM limbs" cookbook | summarize

Under Unix, another alternative is to use tail to skip the first line:

% mysql -e "SELECT arms FROM limbs" cookbook | tail +2 | summarize
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

MySQL Reference Manual

MySQL Reference Manual

Michael Widenius, David Axmark, Kaj Arno
High Performance MySQL

High Performance MySQL

Jeremy D. Zawodny, Derek J. Balling
MySQL Stored Procedure Programming

MySQL Stored Procedure Programming

Guy Harrison, Steven Feuerstein

Publisher Resources

ISBN: 0596001452Catalog PageErrata