`ego` or `go` doesn't work after a SQL statement in MySQL

67 Views Asked by At

First of all, the doc says below:

mysql> help
...
ego       (\G) Send command to mysql server, display result vertically.
...
go        (\g) Send command to mysql server.
...

But, ego or go doesn't work after a SQL statement as shown below:

mysql> SELECT * FROM person
    -> ego

Or:

mysql> SELECT * FROM person
    -> go

While \G or \g works after a SQL statement as shown below:

mysql> SELECT * FROM person
    -> \G
*************************** 1. row ***************************
  id: 1
name: John
*************************** 2. row ***************************
  id: 2
name: David

Or:

mysql> SELECT * FROM person
    -> \g
+----+-------+
| id | name  |
+----+-------+
|  1 | John  |
|  2 | David |
+----+-------+

So, how can I make ego or go work after a SQL statement?

1

There are 1 best solutions below

0
On

You can use --named-commands or -G with login to make ego or go work after a SQL statement as shown below:

mysql -u john -p --named-commands

Or:

mysql -u john -p -G

Or on Windows, you can set named-commands under [mysql] in my.ini as shown below. *My answer explains [mysql] and my answer explains where my.ini is located on Windows:

# "my.ini"

[mysql]
...
named-commands

Then, you can log in by setting my.ini's location to --defaults-file= or --defaults-extra-file= to make ego or go work after a SQL statement as shown below. *--defaults-file= or --defaults-extra-file= must be the 1st option otherwise there is the error:

mysql --defaults-file='C:\ProgramData\MySQL\MySQL Server 8.0\my.ini' -u john -p

Or:

mysql --defaults-extra-file='C:\ProgramData\MySQL\MySQL Server 8.0\my.ini' -u john -p

Finally, ego or go works after a SQL statement as shown below:

mysql> SELECT * FROM person
    -> ego
*************************** 1. row ***************************
  id: 1
name: John
*************************** 2. row ***************************
  id: 2
name: David

Or:

mysql> SELECT * FROM person
    -> go
+----+-------+
| id | name  |
+----+-------+
|  1 | John  |
|  2 | David |
+----+-------+

In addition, ego or go doesn't work just after a SQL statement as shown below:

mysql> SELECT * FROM personego
    ->

Or:

mysql> SELECT * FROM person ego
    ->

Or:

mysql> SELECT * FROM persongo
    ->

Or:

mysql> SELECT * FROM person go
    ->

While \G or \g works just after a SQL statement as shown below:

mysql> SELECT * FROM person\G  
*************************** 1. row ***************************
  id: 1
name: John
*************************** 2. row ***************************
  id: 2
name: David

Or:

mysql> SELECT * FROM person \G  
*************************** 1. row ***************************
  id: 1
name: John
*************************** 2. row ***************************
  id: 2
name: David

Or:

mysql> SELECT * FROM person\g  
+----+-------+
| id | name  |
+----+-------+
|  1 | John  |
|  2 | David |
+----+-------+

Or:

mysql> SELECT * FROM person \g  
+----+-------+
| id | name  |
+----+-------+
|  1 | John  |
|  2 | David |
+----+-------+