MySQL显示操作控制小技巧

MySQL 显现格式化

一、使用G按行垂直显示结果

未使用

mysql> select * from wp_users limit 1,2;

+----+------------------+------------------------------------+------------------+-----------------------------+----------+---------------------+---------------------+-------------+------------------+

| ID | user_login      | user_pass                          | user_nicename    | user_email                  | user_url | user_registered    | user_activation_key | user_status | display_name    |

+----+------------------+------------------------------------+------------------+-----------------------------+----------+---------------------+---------------------+-------------+------------------+

|  2 | NicholaJorgenson | $P$BrLC6ljpc5i6IvCw4V2dTHn.ZTrXd/1 | nicholajorgenson | almatrostelgt3776@yahoo.com |          | 2015-02-15 09:40:54 |                    |          0 | NicholaJorgenson |

|  3 | ElvinMoney      | $P$BebFywousFh0mVmoqHEWAx7IofQmEJ0 | elvinmoney      | alizanoguera@mailcatch.com  |          | 2015-02-15 10:04:36 |                    |          0 | ElvinMoney      |

+----+------------------+------------------------------------+------------------+-----------------------------+----------+---------------------+---------------------+-------------+------------------+

2 rows in set (0.00 sec)

使用

mysql> select * from wp_users limit 1,2\G;

*************************** 1. row ***************************

ID: 2

user_login: NicholaJorgenson

user_pass: $P$BrLC6ljpc5i6IvCw4V2dTHn.ZTrXd/1

user_nicename: nicholajorgenson

user_email: almatrostelgt3776@yahoo.com

user_url: 

user_registered: 2015-02-15 09:40:54

user_activation_key: 

user_status: 0

display_name: NicholaJorgenson

*************************** 2. row ***************************

ID: 3

user_login: ElvinMoney

user_pass: $P$BebFywousFh0mVmoqHEWAx7IofQmEJ0

user_nicename: elvinmoney

user_email: alizanoguera@mailcatch.com

user_url: 

user_registered: 2015-02-15 10:04:36

user_activation_key: 

user_status: 0

display_name: ElvinMoney

2 rows in set (0.00 sec)

二、使用pager来设置翻页

pager 'more'      此模式会显示一页,等待按键再显示一页   

pager 'less'      此模式会显示一页,等待按键再显示一行

nopager            此模式直接显示到最完

三、使用tee保存运行结果到文件,类似于Oracle中的spool命令

mysql> tee test.txt

Logging to file 'test.txt'

select * from wp_users limit 1,2;

mysql> notee

mysql> quit

Bye

[mysql@sam ~]$ cat test.txt

mysql> select * from wp_users limit 1,2;

+----+------------------+------------------------------------+------------------+-----------------------------+----------+---------------------+---------------------+-------------+------------------+

| ID | user_login      | user_pass                          | user_nicename    | user_email                  | user_url | user_registered    | user_activation_key | user_status | display_name    |

+----+------------------+------------------------------------+------------------+-----------------------------+----------+---------------------+---------------------+-------------+------------------+

|  2 | NicholaJorgenson | $P$BrLC6ljpc5i6IvCw4V2dTHn.ZTrXd/1 | nicholajorgenson | almatrostelgt3776@yahoo.com |          | 2015-02-15 09:40:54 |                    |          0 | NicholaJorgenson |

|  3 | ElvinMoney      | $P$BebFywousFh0mVmoqHEWAx7IofQmEJ0 | elvinmoney      | alizanoguera@mailcatch.com  |          | 2015-02-15 10:04:36 |                    |          0 | ElvinMoney      |

+----+------------------+------------------------------------+------------------+-----------------------------+----------+---------------------+---------------------+-------------+------------------+

2 rows in set (0.00 sec)

mysql> notee

[mysql@sam ~]$ 

四、直接执行操作系统命令

mysql> system ls -l

total 10092

-rw-rw-r-- 1 mysql mysql 1638854 Apr 22 16:05 backup1.sql

-rw-rw-r-- 1 mysql mysql 1767787 Apr 23 10:49 backup2.sql

-rw-rw-r-- 1 mysql mysql  13807 Apr 23 09:48 backup3.sql

-rw-rw-r-- 1 mysql mysql  12258 Apr 23 10:53 backup4.sql

-rw-rw-r-- 1 mysql mysql 2293238 Apr 23 11:03 backup5.sql

-rw-rw-r-- 1 mysql mysql 2297583 Apr 23 11:16 backup6.sql

-rw-rw-r-- 1 mysql mysql 2297579 Apr 23 11:23 backup7.sql

-rw-rw-r-- 1 mysql mysql    1280 Aug 26 11:18 test.txt

五、执行SQL文件脚本

mysql> source 1.sql

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/09badaa228b4b8f1a27bee6382fc22be.html