MySQL command line “secret”

Tom Preston-Werner (of Gravatar and Chronic fame) wrote about this neat MySQL command line “trick” where instead of ending your SELECT statements with the usual semi-colon, using a “\G” gives you a very readable output.

mysql> select * from locations where location_code = 'SIN'  limit 1\G
*************************** 1. row ***************************
          location_code: SIN
          location_name: Singapore Changi Apt
multi_airport_city_code: SIN
          location_type: A
      location_sub_type: A
           country_code: SG
             state_code:
                 active: 1
               latitude: 01.22.00N
              longitude: 103.59.00E
1 row in set (0.10 sec)

Very useful, especially when SELECTing multiple fields where the output becomes unfit for visual consumption (you know what I mean, just go SELECT some stuff in your MySQL command line and you’ll see if you don’t).

Comments & TrackBacks (Add yours)

The paper doll icon that precedes each comment is an idea conceived by Vanessa Tan.

Paper doll icon
choonkeat's Gravatar

Wow nice! with a bit of sed, we might be able to make yaml/json out of that. LOL

Posted by: choonkeat on July 21, 2007 12pm

You can subscribe to the RSS feed for comments on this post.

Post a comment

(required)

(required, but never displayed)


You can format your comments using XHTML. Your email address will not be displayed or used for nefarious purposes.

Only following tags are allowed:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>