What I Learned Today: MySQL Shell Commands

This is a quick one that I learned from a co-worker.

Filed under:

This is a quick one that I learned from a co-worker. He was in the MySQL shell and instead of ending his query with a semi-colon, like I normally use, he used \G. The results are interesting, instead of results showing in rows with the fields as columns, results are displayed vertically. Each record is separated by a row number and each field is on a newline with the field name.

"Normal" Query Syntax

SELECT * FROM `actions` LIMIT 3;

| aid                      | type    | callback                 | parameters | label             |
| comment_publish_action   | comment | comment_publish_action   |            | Publish comment   |
| comment_save_action      | comment | comment_save_action      |            | Save comment      |
| comment_unpublish_action | comment | comment_unpublish_action |            | Unpublish comment |

Alternative Vertical Results

SELECT * FROM `actions` LIMIT 3\G

*************************** 1. row ***************************
       aid: comment_publish_action
      type: comment
  callback: comment_publish_action
     label: Publish comment
*************************** 2. row ***************************
       aid: comment_save_action
      type: comment
  callback: comment_save_action
     label: Save comment
*************************** 3. row ***************************
       aid: comment_unpublish_action
      type: comment
  callback: comment_unpublish_action
     label: Unpublish comment

Other Quick Commands

Also, you can use \g in place of a semi-colon. Another one I found on the MySQL command list page just now was \e, which opens your text editor and allows you to edit the query. I know I can use this when I mistype part of a query that I was breaking up into multiple lines.

Similar posts

Get notified on new marketing insights

Be the first to know about new B2B SaaS Marketing insights to build or refine your marketing function with the tools and knowledge of today’s industry.