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
Release: 2024-11-17 15:05:02
Original
1022 people have browsed it

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 ...
Copy after login

For example:

mysql -N use testdb
mysql -N select * from names;
Copy after login

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  |
+------+-------+
Copy after login

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;
Copy after login

Output:

id  name
1   pete
2   john
3   mike
Copy after login

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

mysql -sN ...
Copy after login

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!

source:php.cn
Statement of this Website
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
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template