How does `\G` format output?

QuestionsQuestions8 SkillsProDec, 23 2025
0107

In MySQL/MariaDB, using \G instead of a semicolon (;) at the end of a command changes the output from a horizontal table to a vertical list.

The Main Difference

  • Standard ; (Horizontal): Data is displayed in columns. If a table has many columns (like SHOW TABLE STATUS), the text often "wraps" around the screen, making it very messy and hard to read.
  • Vertical \G (Vertical): Each row is displayed as a separate block, and each column is shown on a new line.

Comparison

If you run SHOW TABLE STATUS;, it looks like a jumble of text. By using \G, it looks like this:

SHOW TABLE STATUS FROM store\G

Output:

*************************** 1. row ***************************
           Name: products
         Engine: InnoDB
        Version: 10
     Row_format: Dynamic
           Rows: 0
 Avg_row_length: 0
    Data_length: 16384
Max_data_length: 0
   Index_length: 16384
      Data_free: 0
 Auto_increment: 1
    Create_time: 2023-10-27 10:00:00
    Update_time: NULL
     Check_time: NULL
      Collation: utf8mb3_general_ci
       Checksum: NULL
 Create_options: 
        Comment: 

Why use it?

  1. Readability: It is essential when a table has many columns (like the INFORMATION_SCHEMA tables or SHOW TABLE STATUS).
  2. No Wrapping: You don't have to scroll horizontally or deal with broken lines in your terminal.
  3. Quick Inspection: It’s much easier to scan a vertical list for a specific value (like Rows or Auto_increment) than a wide table.

Note: You do not need a semicolon when using \G. The \G acts as the terminator for the command. Give it a try on your current task

0 Comments

no data
Be the first to share your comment!