MySQL command line “secret”

In: Neat Stuff|Web development

19 Jul 2007

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

1 Response to MySQL command line “secret”



July 21st, 2007 at 12pm

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