48

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.

AZinkey
  • 5,209
  • 5
  • 28
  • 46

2 Answers2

77

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)
Ravinder Reddy
  • 23,692
  • 6
  • 52
  • 82
  • 6
    Or... if you get tired of typing \G all the time you can just run mysql from the command line with the `--vertical` or even `--auto-vertical-output` parameters. – ingenious May 15 '16 at 20:56
  • @ingenious that should just be it's own answer as for me "MySQL command line" is usually things like `mysql -e "select * from nova.instances where uuid='abcdef';"` and plopping --vertical seems more sensible for me (if verbose? I dunno, personal preference, + it's more explicit) – Nick T Feb 14 '17 at 20:25
4

Maybe you are using an older version of MySQL? \G is a shortcut for the MySQL ego command and should work on your system as well.

See: http://dev.mysql.com/doc/refman/5.5/en/mysql-commands.html

And it works fine with vertical display on on my system.

Ronan Boiteau
  • 9,608
  • 6
  • 34
  • 56
Matijs
  • 2,533
  • 20
  • 24
  • True, just learned we need to start "mysql" client with `--named-commands` options to use the longer forms "go" and "ego". https://lefred.be/content/mysql-command-delimiter-curiosity-go-ego/ – Mister_Tom Mar 02 '20 at 15:58