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 online protection

Rails Long Term Support

Rails LTS provides security patches for old versions of Ruby on Rails (2.3, 3.2, 4.2 and 5.2)

  • Prevents you from data breaches and liability risks
  • Upgrade at your own pace
  • Works with modern Rubies
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)