Suppressing Column Headers in a SQL Query
In database operations, presenting query results with column headers provides context for the data displayed. However, there may be scenarios where suppressing these headers is desirable. This question addresses the possibility of disabling column headers for a specific SQL statement while executing multiple queries in batch using the MySQL command-line binary.
Solution
To omit column headers in a single SQL statement, invoking MySQL with the -N (alias for --skip-column-names) option is the key. The following command exemplifies this usage:
mysql -N ...
Consider the following example:
mysql -N ... use testdb; select * from names;
This command will produce results without the column headers:
+------+-------+ | 1 | pete | | 2 | john | | 3 | mike | +------+-------+ 3 rows in set (0.00 sec)
Furthermore, to remove the grid (vertical and horizontal lines) surrounding the results, the -s (--silent) option can be employed. This will separate columns with a TAB character:
mysql -s ... use testdb; select * from names; id name 1 pete 2 john 3 mike
Finally, to display data without headers or grid, simply use both -s and -N.
mysql -sN ...
The above is the detailed content of How to Suppress Column Headers in MySQL Queries?. For more information, please follow other related articles on the PHP Chinese website!