Suppressing Header Output for a Specific SQL Statement
When executing multiple SQL statements in batch mode using the mysql command-line tool, scenarios may arise where you desire to suppress the display of column headers for a particular SELECT statement. This article explores how to achieve this behavior effectively.
To suppress column headers for a single SELECT statement, invoke mysql with the -N option (or its alias, -skip-column-names):
mysql -N ...
For instance, consider the following batch of SQL statements:
use testdb; select * from names; # Display column headers select * from names; # Suppress column headers
Executing this batch with the -N option applied to the second SELECT statement would produce the following output:
+------+-------+ | id | name | +------+-------+ | 1 | pete | | 2 | john | | 3 | mike | +------+-------+ 3 rows in set (0.00 sec) pete john mike
As evident, column headers are displayed for the first SELECT statement but not for the second.
To further enhance the output presentation, you can employ the -s (or --silent) option to remove the grid surrounding the results, separating columns with TAB characters:
mysql -sN ...
Alternatively, you can utilize both -s and -N simultaneously to remove both headers and the grid, producing a barebones output without any unnecessary formatting:
mysql -sN ...
The above is the detailed content of How to Suppress Header Output for a Specific SQL Statement in MySQL?. For more information, please follow other related articles on the PHP Chinese website!