Home >Database >Mysql Tutorial >How to suppress column headers when executing a single SQL statement in a batch using `mysql` command-line?

How to suppress column headers when executing a single SQL statement in a batch using `mysql` command-line?

Barbara Streisand
Barbara StreisandOriginal
2024-11-17 15:05:021019browse

How to suppress column headers when executing a single SQL statement in a batch using `mysql` command-line?

How to Suppress Column Header Output for a Single SQL Statement

When executing multiple SQL statements in batch using the mysql command-line binary, you may encounter situations where you want to suppress the column headers for a particular SELECT statement. Here's how to achieve this:

Invoke mysql with the -N option (or its alias --skip-column-names):

mysql -N ...

For example:

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

This will suppress the column headers for the SELECT statement, resulting in output that only displays the selected records:

+------+-------+
|    1 | pete  |
|    2 | john  |
|    3 | mike  |
+------+-------+

To further enhance the presentation, you can use the -s (--silent) option to remove the grid (vertical and horizontal lines) around the results, separating columns with a TAB character:

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

Output:

id  name
1   pete
2   john
3   mike

Combining both -s and -N will produce data with no headers and no grid:

mysql -sN ...

The above is the detailed content of How to suppress column headers when executing a single SQL statement in a batch using `mysql` command-line?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn