MySQL \G formats results in rows

Using the \G qualifier at the end of a MySQL select statement will format the results with the column name and column value in each row of your result.  This makes it MUCH easier to read a single row of a table that has many columns.

Example:

mysql> select * from routines where routine_name=’myRoutine’ \G

*************************** 1. row ***************************
     SPECIFIC_NAME: myRoutine
   ROUTINE_CATALOG: NULL
    ROUTINE_SCHEMA: myDatabase
      ROUTINE_NAME: myRoutine
      ROUTINE_TYPE: PROCEDURE
    DTD_IDENTIFIER: NULL
      ROUTINE_BODY: SQL
ROUTINE_DEFINITION: NULL
     EXTERNAL_NAME: NULL
 EXTERNAL_LANGUAGE: NULL
   PARAMETER_STYLE: SQL
  IS_DETERMINISTIC: NO
   SQL_DATA_ACCESS: CONTAINS SQL
          SQL_PATH: NULL
     SECURITY_TYPE: DEFINER
           CREATED: 2010-10-08 22:36:55
      LAST_ALTERED: 2010-10-08 22:36:55
          SQL_MODE: STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER
   ROUTINE_COMMENT:
           DEFINER: root@127.0.0.1

I’m posting this in my blog because it’s a trick I have lost and found at least twice, and don’t want to forget it again.  This particular time I had to go to the #mysql channel on IRC to get my answer.  I always seem to have a hard time describing this trick well enough for google to find me an answer.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s