Posted over 8 years ago. Visible to the public.

MySQL shell: Vertical vs horizontal layout

When talking to your MySQL server via a mysql shell, you can terminate queries by ; or \G -- the latter gives you a vertical output.

You know this:

mysql> SELECT * FROM users; +----+---------+---------------------+-----------------+ | id | name | email | greeting | +----+---------+---------------------+-----------------+ | 1 | Alice | | Hello world! | | 2 | Bob | | Hello universe! | | 3 | Charlie | | Hi mom! | +----+---------+---------------------+-----------------+ 3 rows in set (0.00 sec)

This is how it looks like vertically:

mysql> SELECT * FROM users \G *************************** 1. row *************************** id: 1 name: Alice email: greeting: Hello world! *************************** 2. row *************************** id: 2 name: Bob email: greeting: Hello universe! *************************** 3. row *************************** id: 3 name: Charlie email: greeting: Hi mom! 3 rows in set (0.00 sec)

Sometimes, using the vertical output makes more sense. It is helpful for results with lots of columns or when you have one column with lots of content that breaks the "table" layout on your terminal.

Fun fact: Don't confuse \G with \g which is the same as using a semicolon.

Growing Rails Applications in Practice
Check out our new e-book:
Learn to structure large Ruby on Rails codebases with the tools you already know and love.

Owner of this card:

Arne Hartherz
Last edit:
over 8 years ago
About this deck:
We are makandra and do test-driven, agile Ruby on Rails software development.
License for source code
Posted by Arne Hartherz to makandra dev
This website uses short-lived cookies to improve usability.
Accept or learn more