The \G modifier in the MySQL command line client

February 27, 2009 · Posted in MySQL 

A little publicized, but exceedingly useful feature of the MySQL command line client is the \G modifier. It formats the query output nicely, so you can read through it easier. To use it, you just replace the semi-colon at the end of the query with ‘\G’.

For example, checking the master status:

mysql> SHOW MASTER STATUS;
+------------------+----------+--------------+------------------+
| File             | Position | Binlog_Do_DB | Binlog_Ignore_DB |
+------------------+----------+--------------+------------------+
| mysql-bin.000193 |     7061 |              |                  |
+------------------+----------+--------------+------------------+
1 row IN SET (0.00 sec)
 
mysql> SHOW MASTER STATUS\G
*************************** 1. row ***************************
            File: mysql-bin.000193
        Position: 7061
    Binlog_Do_DB:
Binlog_Ignore_DB:
1 row IN SET (0.00 sec)

Now try this for the much larger SHOW SLAVE STATUS. Or for the enormous SHOW ENGINE INNODB STATUS.

As you can see, this is a handy option to make your console output much easier to read.

  • Digg
  • del.icio.us
  • Facebook
  • Google Bookmarks
  • LinkedIn
  • MySpace
  • Reddit
  • Slashdot
  • Technorati
  • TwitThis

Comments

2 Responses to “The \G modifier in the MySQL command line client”

  1. Sheeri Cabral on February 27th, 2009 2:42 pm

    You can use

    mysql -E
    or
    mysql –vertical

    The holy grail is

    mysql –auto-vertical-output

    Which does what it says: if the output is wider than your terminal, it displays in vertical format.

  2. Shantanu Oak on March 18th, 2009 1:28 pm

    You can also watch the data changing. Try…
    watch –interval=1 –differences ‘mysql -uuser -ppassword -e “show slave status\G”‘

Leave a Reply




  • Gary Pendergast, noun: Gamer, developer, MySQL, WordPress, web and music geek. Currently taking a leave of absence from life as a MySQL Support Engineer for Oracle to tour around Europe. Can be observed in his natural habit at pento.net, or usually in Bologna, Italy.

  • My Twitter