Read more

MySQL shell: Vertical vs horizontal layout

Arne Hartherz
April 03, 2012Software engineer at makandra GmbH

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

Illustration book lover

Growing Rails Applications in Practice

Check out our e-book. Learn to structure large Ruby on Rails codebases with the tools you already know and love.

  • Introduce design conventions for controllers and user-facing models
  • Create a system for growth
  • Build applications to last
Read more Show archive.org snapshot

You know this:

mysql> SELECT * FROM users;
+----+---------+---------------------+-----------------+
| id | name    | email               | greeting        |
+----+---------+---------------------+-----------------+
|  1 | Alice   | alice@example.com   | Hello world!    |
|  2 | Bob     | bob@example.com     | Hello universe! |
|  3 | Charlie | charlie@example.com | 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: alice@example.com
greeting: Hello world!
*************************** 2. row ***************************
      id: 2
    name: Bob
   email: bob@example.com
greeting: Hello universe!
*************************** 3. row ***************************
      id: 3
    name: Charlie
   email: charlie@example.com
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.

Posted by Arne Hartherz to makandra dev (2012-04-03 13:42)