mysql操作命令梳理(3)-pager
生活随笔
收集整理的這篇文章主要介紹了
mysql操作命令梳理(3)-pager
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
?
在mysql日常操作中,妙用pager設置顯示方式,可以大大提高工作效率。比如select出來的結果集超過幾個屏幕,那么前面的結果一晃而過無法看到,這時候使用pager可以設置調用os的more或者less等顯示查詢結果,和在os中使用more或者less查看大文件的效果一樣。
pager用法:
實際上等于將它設置以后的所有mysql操作命令的輸出通過pager設置命令執行,類似于管道符的作用
nopager命令:取消pager設置,恢復之前的輸出狀態。(如果不設置nopager,那么只能通過重啟mysql服務才能恢復了)
舉些例子來說明吧:
1)當處理大量數據時,不想顯示查詢的結果,而只需知道查詢花費的時間。
mysql> nopager; //恢復之前的輸出狀態 PAGER set to stdout
mysql> select * from huanqiu.haha; +----+------------+ | id | name | +----+------------+ | 1 | wangshibo | | 2 | wangshikui | | 3 | wangjuan | | 4 | wangman | | 11 | wangshikui | +----+------------+ 5 rows in set (0.00 sec)
2)如果有大量連接,用show processlist看不方便,想看有多少Sleep狀態,則可以用pager。
mysql> show processlist; +------+-------+---------------------+--------+-------------+------+-----------------------------------------------------------------------+------------------+ | Id | User | Host | db | Command | Time | State | Info | +------+-------+---------------------+--------+-------------+------+-----------------------------------------------------------------------+------------------+ | 5 | root | localhost | huanpc | Query | 0 | init | show processlist | | 1801 | slave | 192.168.1.102:37125 | NULL | Binlog Dump | 9904 | Master has sent all binlog to slave; waiting for binlog to be updated | NULL | +------+-------+---------------------+--------+-------------+------+-----------------------------------------------------------------------+------------------+ 2 rows in set (0.00 sec)mysql> pager grep Sleep |wc -l; PAGER set to 'grep Sleep |wc -l' mysql> show processlist; //類似于show processlist結果再通過grep Sleep |wc -l顯示;下面表示一共有2個連接,其中0個Sleep狀態的連接。 0 2 rows in set (0.00 sec) mysql> nopager; //恢復之前的輸出狀態3)設置pager,只查看slave狀態的幾個status值。
mysql> show slave status \G; //其中的\G表示顯示要換行顯示 *************************** 1. row ***************************Slave_IO_State: Waiting for master to send eventMaster_Host: 192.168.1.101Master_User: slaveMaster_Port: 3306Connect_Retry: 60Master_Log_File: mysql-bin.000001Read_Master_Log_Pos: 5370489Relay_Log_File: mysql-relay-bin.000005Relay_Log_Pos: 2476520Relay_Master_Log_File: mysql-bin.000001Slave_IO_Running: YesSlave_SQL_Running: YesReplicate_Do_DB: huanqiu,huanpcReplicate_Ignore_DB: mysqlReplicate_Do_Table: Replicate_Ignore_Table: Replicate_Wild_Do_Table: Replicate_Wild_Ignore_Table: Last_Errno: 0Last_Error: Skip_Counter: 0Exec_Master_Log_Pos: 5370489Relay_Log_Space: 2476693Until_Condition: NoneUntil_Log_File: Until_Log_Pos: 0Master_SSL_Allowed: NoMaster_SSL_CA_File: Master_SSL_CA_Path: Master_SSL_Cert: Master_SSL_Cipher: Master_SSL_Key: Seconds_Behind_Master: 0 Master_SSL_Verify_Server_Cert: NoLast_IO_Errno: 0Last_IO_Error: Last_SQL_Errno: 0Last_SQL_Error: Replicate_Ignore_Server_Ids: Master_Server_Id: 101Master_UUID: b667a58f-d6e0-11e6-8c0a-fa163e2d66acMaster_Info_File: /data/mysql/data/master.infoSQL_Delay: 0SQL_Remaining_Delay: NULLSlave_SQL_Running_State: Slave has read all relay log; waiting for the slave I/O thread to update itMaster_Retry_Count: 86400Master_Bind: Last_IO_Error_Timestamp: Last_SQL_Error_Timestamp: Master_SSL_Crl: Master_SSL_Crlpath: Retrieved_Gtid_Set: Executed_Gtid_Set: Auto_Position: 0 1 row in set (0.00 sec)ERROR: No query specifiedmysql> pager cat | egrep -i 'system user|Exec_Master_Log_Pos|Seconds_Behind_Master|Read_Master_Log_Pos'; PAGER set to 'cat | egrep -i 'system user|Exec_Master_Log_Pos|Seconds_Behind_Master|Read_Master_Log_Pos''mysql> show slave status \G;Read_Master_Log_Pos: 5370489Exec_Master_Log_Pos: 5370489Seconds_Behind_Master: 0 1 row in set (0.00 sec)ERROR: No query specifiedmysql> nopager; //恢復之前的顯示狀態 PAGER set to stdout?
總結
以上是生活随笔為你收集整理的mysql操作命令梳理(3)-pager的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 只用来保存JQuery lightbox
- 下一篇: .NET url 的编码与解码