Search code examples
mysqlcmdcommand-prompt

How to show records vertically in mysql command line?


First explaining what is on my mind {I'm not good at English}

On Alan Storm's blog, I found a tricky thing about mysql. I am not sure if he's using the command line or not. The comment section has closed over there, so I'm putting this query here instead.

mysql> select * from eav_entity_type\G

When I run this statement in my command line (Window dos based cmd) I just return normal select statement results.

Please let me know how could I get result as shown in that blog or if it is just part of a code beautifier.


Solution

  • I think you are using \g instead of \G. Unless you use \G you get default output pattern. Default is \g.

    mysql> show databases\g
    +--------------------+
    | Database           |
    +--------------------+
    | information_schema |
    | mysql              |
    | test               |
    +--------------------+
    3 rows in set (0.00 sec)
    
    mysql> show databases\G
    *************************** 1. row ***************************
    Database: information_schema
    *************************** 2. row ***************************
    Database: mysql
    *************************** 3. row ***************************
    Database: test
    3 rows in set (0.00 sec)
    

    EDIT: some more better examples:

    this is default output:

    mysql> desc reviews_by_device;
    
    +----------------------+--------------+------+-----+---------+----------------+
    | Field                | Type         | Null | Key | Default | Extra          |
    +----------------------+--------------+------+-----+---------+----------------+
    | ar_id                | int(10)      | NO   | PRI | NULL    | auto_increment |
    | ar_pkg_name          | varchar(50)  | YES  |     | NULL    |                |
    | ar_ver_code          | int(5)       | YES  |     | NULL    |                |
    | ar_ver_name          | float(3,2)   | YES  |     | NULL    |                |
    | ar_rev_lang          | varchar(10)  | YES  |     | NULL    |                |
    | ar_device            | varchar(250) | YES  |     | NULL    |                |
    | ar_rev_submit_dttm   | datetime     | YES  |     | NULL    |                |
    | ar_rev_submit_milli  | varchar(20)  | YES  |     | NULL    |                |
    | ar_rev_last_updttm   | datetime     | YES  |     | NULL    |                |
    | ar_rev_last_updmilli | varchar(20)  | YES  |     | NULL    |                |
    | ar_star_rating       | int(1)       | YES  |     | NULL    |                |
    | ar_rev_title         | varchar(250) | YES  |     | NULL    |                |
    | ar_rev_Text          | mediumtext   | YES  |     | NULL    |                |
    | ar_dev_rpl_dttm      | datetime     | YES  |     | NULL    |                |
    | ar_dev_rpl_milli     | varchar(20)  | YES  |     | NULL    |                |
    | ar_dev_rpl_text      | mediumtext   | YES  |     | NULL    |                |
    | ar_rev_link          | varchar(250) | YES  |     | NULL    |                |
    +----------------------+--------------+------+-----+---------+----------------+
    17 rows in set (0.00 sec)
    

    this is vertical report by ego command use:

    mysql> desc reviews_by_device\G
    
    *************************** 1. row ***************************
      Field: ar_id
       Type: int(10)
       Null: NO
        Key: PRI
    Default: NULL
      Extra: auto_increment
    *************************** 2. row ***************************
      Field: ar_pkg_name
       Type: varchar(50)
       Null: YES
        Key:
    Default: NULL
      Extra:
    *************************** 3. row ***************************
      Field: ar_ver_code
       Type: int(5)
       Null: YES
        Key:
    Default: NULL
      Extra:
    *************************** 4. row ***************************
    ...
    17 rows in set (0.00 sec)