MySQL shell: Vertical vs horizontal layout

Posted . Visible to the public.

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   | 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.

Arne Hartherz
Last edit
License
Source code in this card is licensed under the MIT License.
Posted by Arne Hartherz to makandra dev (2012-04-03 11:42)