Printing MySQL Output Without Headers or Column Separators

Print MySQL Output Without Headers or Column Separators

Estimated reading time: 2 minutes

Clean and formatted output is essential in data processing, automation, and scripting. This guide will show you how to print MySQL output without headers or column separators using the MySQL command-line client options.

Why Print MySQL Output Without Headers or Column Separators?

When working with MySQL, there are times when you need raw data without any additional formatting. This is particularly useful for automation scripts, data exports, and integrating MySQL output into other tools or systems.

CLI Options to Print MySQL Output Without Headers or Column Separators

To achieve this, you’ll use a combination of MySQL command-line options. Here’s how:

  1. -N Option: This option tells MySQL not to print column names in the output.
  2. --silent and --batch Options: These options suppress additional formatting, making the output suitable for scripting.

Example Command

Here’s a basic example of a MySQL command to get output without headers or column separators:

In this command, we are passing the following options:

  • -u username -p: Ask for the MySQL username and password.
  • -N: Do not display column names in the output.
  • -e: Execute the specified SQL query.
  • --silent and --batch: Do not display additional formatting or column separators.

You can also use the -s shorthand option instead of the --slient flag, which does the same thing. The same MySQL command we saw above would look something like this with the -s flag:

Example outputs

Without passing the -s and -N flags, the MySQL CLI output would look something like this:

When you pass the -s and -N flags, the MySQL CLI will print MySQL output without headers or column separators.

Further reading

Leave a Reply

Your email address will not be published. Required fields are marked *