您可以使用反斜杠后跟G即\ G代替分号(;)。语法如下所示,以在MySQL命令行中垂直显示记录。
SELECT *FROM yourTableName\G
为了理解上述语法,让我们创建一个表。创建表的查询如下
mysql> create table showRecordsVertically -> ( -> Id int, -> Name varchar(100), -> Age int -> );
使用insert命令在表中插入一些记录。查询如下
mysql> insert into showRecordsVertically values(101,'John',23); mysql> insert into showRecordsVertically values(104,'Carol',20); mysql> insert into showRecordsVertically values(107,'Bob',22); mysql> insert into showRecordsVertically values(110,'David',29); mysql> insert into showRecordsVertically values(113,'Mike',28);
现在,您可以使用\ G垂直显示记录。查询如下
mysql> select *from showRecordsVertically\G
以下是输出
*************************** 1. row *************************** Id: 101 Name: John Age: 23 *************************** 2. row *************************** Id: 104 Name: Carol Age: 20 *************************** 3. row *************************** Id: 107 Name: Bob Age: 22 *************************** 4. row *************************** Id: 110 Name: David Age: 29 *************************** 5. row *************************** Id: 113 Name: Mike Age: 28 5 rows in set (0.00 sec)