Skip to main content

How to Show MySQL Query Results Vertically with \G

· 5 min read
Jagdish Kumawat
Founder @ Dewiride

A table with a dozen columns doesn't fit in a terminal, and the mysql client's boxed output wraps into lines nobody can read. Ending the statement with \G instead of ; prints each row vertically, one column: value per line. This guide shows the difference on a real MySQL 9.7 table, and the client option that makes every result vertical.

Prerequisites​

Terminal
docker compose exec mysql mysql --user=inventory_app --password inventory

Step 1: See the Problem​

The products table has twelve columns. Asking for one product the usual way:

mysql>
SELECT * FROM products WHERE Sku = 'ADP-HDMI-01';
Output
+----+-------------+-----------------------+-------------+------------+-----------+----------------+--------------+------------+---------------+----------------------------+----------------------------+
| Id | Sku | Name | Description | CategoryId | UnitPrice | QuantityOnHand | ReorderLevel | IsArchived | ArchivedAtUtc | CreatedAtUtc | UpdatedAtUtc |
+----+-------------+-----------------------+-------------+------------+-----------+----------------+--------------+------------+---------------+----------------------------+----------------------------+
| 3 | ADP-HDMI-01 | USB-C to HDMI adapter | | 6 | 20.00 | 8 | 2 | 0 | NULL | 2026-11-03 04:35:17.483586 | 2026-11-03 04:35:17.483586 |
+----+-------------+-----------------------+-------------+------------+-----------+----------------+--------------+------------+---------------+----------------------------+----------------------------+
1 row in set (0.000 sec)

That's 200 characters per line. In a normal terminal window, each line wraps two or three times, and matching a value to its column becomes guesswork.

Step 2: End It with \G​

Same statement, with \G in place of the semicolon:

mysql>
SELECT * FROM products WHERE Sku = 'ADP-HDMI-01'\G
Output
*************************** 1. row ***************************
Id: 3
Sku: ADP-HDMI-01
Name: USB-C to HDMI adapter
Description:
CategoryId: 6
UnitPrice: 20.00
QuantityOnHand: 8
ReorderLevel: 2
IsArchived: 0
ArchivedAtUtc: NULL
CreatedAtUtc: 2026-11-03 04:35:17.483586
UpdatedAtUtc: 2026-11-03 04:35:17.483586
1 row in set (0.000 sec)

The mysql client printing the same products row twice: first as a 200-character-wide table, then with \G as a vertical list of twelve column: value lines.

Each row starts with a line of stars and its number, then one line per column: the name, right-aligned, a colon, and the value. Nothing wraps. The manual's mysql commands page describes \G (also called ego) as: "Send the current statement to the server to be executed and display the result using vertical format."

\G replaces the semicolon; don't type both. SELECT … \G; runs the statement vertically, then prints ERROR: and No query specified, because the client sees an empty statement after the \G.

Where \G Helps Most​

StatementWhy
SHOW CREATE TABLE products\GThe definition is one huge value. Vertically, it prints as readable SQL
SHOW INDEX FROM products\GFifteen columns per index
SELECT * FROM … WHERE Id = …\GOne wide row

For many short rows, keep the semicolon: a narrow table of 50 rows is easier to scan than 50 vertical blocks.

Step 3: Make Every Result Vertical​

When you run a single query from your own terminal, the --vertical option (short form -E) prints every result vertically, with no \G needed:

Terminal
docker compose exec mysql mysql --user=inventory_app --password --vertical --execute="SELECT Id, Name, CreatedAtUtc FROM categories;" inventory
Output
Enter password:
*************************** 1. row ***************************
Id: 1
Name: Desks
CreatedAtUtc: 2026-11-03 05:12:30.635562
*************************** 2. row ***************************
Id: 2
Name: Shelves
CreatedAtUtc: 2026-11-03 05:12:36.577716

The manual's option page describes it: "Print query output rows vertically (one line per column value). Without this option, you can specify vertical output for individual statements by terminating them with \G." It works the same for an interactive session: start the client with --vertical and every result is vertical.

Common Mistakes​

MistakeWhat happensDo this instead
Typing \G;The result, then ERROR: and No query specified for the empty statement after itUse \G alone
Lowercase \gRuns the statement as a normal tableUse uppercase \G
Using \G for long listsPages of blocks that are hard to scanKeep ; and choose fewer columns

Troubleshooting​

SymptomLikely causeFix
\G doesn't work in a GUI toolIt's a command of the mysql client, not SQLUse the tool's own record view

FAQ​

Is \G part of SQL?​

No. It's a command of the mysql client, which it handles itself, then sends the statement to the server. Other tools don't understand it.

What's the lowercase \g?​

\g is the same as a semicolon: it runs the statement with normal table output. Only the uppercase \G is vertical.

Conclusion​

End a statement with \G instead of ; and the mysql client prints each row as a vertical list of column: value lines, which is what wide rows, SHOW CREATE TABLE and SHOW INDEX need. Start the client with --vertical (-E) to make every result vertical.

Additional Resources​

Stay Updated

Subscribe to our newsletter for the latest tutorials, tech insights, and developer news.

By subscribing, you agree to our privacy policy. Unsubscribe at any time.