pager 命令
https://www.percona.com/blog/2013/01/21/fun-with-the-mysql-pager-command/
Last time I wrote about a few tips that can make you more efficient when using the command line on Unix. Today I want to focus more on pager.
The most common usage of pager is to set it to a Unix pager such as less. It can be very useful to view the result of a command spanning over many lines (for instance SHOW ENGINE INNODB STATUS
):
mysql> pager less;
PAGER set to 'less'
mysql> show engine innodb status\G *************************** . row ***************************
Type: InnoDB
Name:
Status:
=====================================
-- :: 2ab7b4f90940 INNODB MONITOR OUTPUT
=====================================
Per second averages calculated from the last seconds
-----------------
BACKGROUND THREAD
-----------------
srv_master_thread loops: srv_active, srv_shutdown, srv_idle
srv_master_thread log flush and writes:
----------
SEMAPHORES
----------
----------
MUTEX INFO
----------
Locked mutex: addr 0x1829940 thread file /usr/src/mysql-5.6./storage/innobase/handler/ha_innodb.cc line
Locked mutex: addr 0x18298c0 thread file /usr/src/mysql-5.6./storage/innobase/srv/srv0srv.cc line
Total number of mutexes
-------------
:
Now you are inside less
and you can easily navigate through the result set (use q to quit, space to scroll down, etc).
Reminder: if you want to leave your custom pager, this is easy, just run pager
:
mysql> pager
Default pager wasn't set, using stdout.
2.\n
:
mysql> \n
PAGER set to stdout
But the pager command is not restricted to such basic usage! You can pass the output of queries to most Unix programs that are able to work on text. We have discussed the topic, but here are a few more examples.
Discarding the result set
Sometimes you don’t care about the result set, you only want to see timing information. This can be true if you are trying different execution plans for a query by changing indexes. Discarding the result is possible with pager:
mysql> pager cat > /root/.txt
mysql> pager cat > /dev/null
PAGER set to 'cat > /dev/null'
mysql> show engine innodb status\G
row in set (0.03 sec)
Now it’s much easier to see all the timing information on one screen.
Comparing result sets
Let’s say you are rewriting a query and you want to check if the result set is the same before and after rewrite. Unfortunately, it has a lot of rows:
mysql> select * from COLLATIONS ;
+--------------------------+--------------------+-----+------------+-------------+---------+
| COLLATION_NAME | CHARACTER_SET_NAME | ID | IS_DEFAULT | IS_COMPILED | SORTLEN |
+--------------------------+--------------------+-----+------------+-------------+---------+
| big5_chinese_ci | big5 | | Yes | Yes | |
| big5_bin | big5 | | | Yes | |
| dec8_swedish_ci | dec8 | | Yes | Yes | |
| dec8_bin | dec8 | | | Yes | |
| cp850_general_ci | cp850 | | Yes | Yes | |
| cp850_bin | cp850 | | | Yes | |
| hp8_english_ci | hp8 | | Yes | Yes | |
| hp8_bin | hp8 | | | Yes | |
| koi8r_general_ci | koi8r | | Yes | Yes | |
| koi8r_bin | koi8r | | | Yes | |
| latin1_german1_ci | latin1 | | | Yes | |
| latin1_swedish_ci | latin1 | | Yes | Yes | |
| latin1_danish_ci | latin1 | | | Yes | |
| latin1_german2_ci | latin1 | | | Yes | |
| latin1_bin | latin1 | | | Yes | |
| latin1_general_ci | latin1 | | | Yes | |
| latin1_general_cs | latin1 | | | Yes | |
| latin1_spanish_ci | latin1 | | | Yes | |
| latin2_czech_cs | latin2 | | | Yes | |
| latin2_general_ci | latin2 | | Yes | Yes | |
| latin2_hungarian_ci | latin2 | | | Yes | |
| latin2_croatian_ci | latin2 | | | Yes | |
| latin2_bin | latin2 | | | Yes | |
| swe7_swedish_ci | swe7 | | Yes | Yes | |
| swe7_bin | swe7 | | | Yes | |
| ascii_general_ci | ascii | | Yes | Yes | |
| ascii_bin | ascii | | | Yes | |
| ujis_japanese_ci | ujis | | Yes | Yes | |
| ujis_bin | ujis | | | Yes | |
| sjis_japanese_ci | sjis | | Yes | Yes | |
| sjis_bin | sjis | | | Yes | |
| hebrew_general_ci | hebrew | | Yes | Yes | |
| hebrew_bin | hebrew | | | Yes | |
| tis620_thai_ci | tis620 | | Yes | Yes | |
| tis620_bin | tis620 | | | Yes | |
| euckr_korean_ci | euckr | | Yes | Yes | |
| euckr_bin | euckr | | | Yes | |
| koi8u_general_ci | koi8u | | Yes | Yes | |
| koi8u_bin | koi8u | | | Yes | |
| gb2312_chinese_ci | gb2312 | | Yes | Yes | |
| gb2312_bin | gb2312 | | | Yes | |
| greek_general_ci | greek | | Yes | Yes | |
| greek_bin | greek | | | Yes | |
| cp1250_general_ci | cp1250 | | Yes | Yes | |
| cp1250_czech_cs | cp1250 | | | Yes | |
| cp1250_croatian_ci | cp1250 | | | Yes | |
| cp1250_bin | cp1250 | | | Yes | |
| cp1250_polish_ci | cp1250 | | | Yes | |
| gbk_chinese_ci | gbk | | Yes | Yes | |
| gbk_bin | gbk | | | Yes | |
| latin5_turkish_ci | latin5 | | Yes | Yes | |
| latin5_bin | latin5 | | | Yes | |
| armscii8_general_ci | armscii8 | | Yes | Yes | |
| armscii8_bin | armscii8 | | | Yes | |
| utf8_general_ci | utf8 | | Yes | Yes | |
| utf8_bin | utf8 | | | Yes | |
| utf8_unicode_ci | utf8 | | | Yes | |
| utf8_icelandic_ci | utf8 | | | Yes | |
| utf8_latvian_ci | utf8 | | | Yes | |
| utf8_romanian_ci | utf8 | | | Yes | |
| utf8_slovenian_ci | utf8 | | | Yes | |
| utf8_polish_ci | utf8 | | | Yes | |
| utf8_estonian_ci | utf8 | | | Yes | |
| utf8_spanish_ci | utf8 | | | Yes | |
| utf8_swedish_ci | utf8 | | | Yes | |
| utf8_turkish_ci | utf8 | | | Yes | |
| utf8_czech_ci | utf8 | | | Yes | |
| utf8_danish_ci | utf8 | | | Yes | |
| utf8_lithuanian_ci | utf8 | | | Yes | |
| utf8_slovak_ci | utf8 | | | Yes | |
| utf8_spanish2_ci | utf8 | | | Yes | |
| utf8_roman_ci | utf8 | | | Yes | |
| utf8_persian_ci | utf8 | | | Yes | |
| utf8_esperanto_ci | utf8 | | | Yes | |
| utf8_hungarian_ci | utf8 | | | Yes | |
| utf8_sinhala_ci | utf8 | | | Yes | |
| utf8_german2_ci | utf8 | | | Yes | |
| utf8_croatian_ci | utf8 | | | Yes | |
| utf8_unicode_520_ci | utf8 | | | Yes | |
| utf8_vietnamese_ci | utf8 | | | Yes | |
| utf8_general_mysql500_ci | utf8 | | | Yes | |
| ucs2_general_ci | ucs2 | | Yes | Yes | |
| ucs2_bin | ucs2 | | | Yes | |
| ucs2_unicode_ci | ucs2 | | | Yes | |
| ucs2_icelandic_ci | ucs2 | | | Yes | |
| ucs2_latvian_ci | ucs2 | | | Yes | |
| ucs2_romanian_ci | ucs2 | | | Yes | |
| ucs2_slovenian_ci | ucs2 | | | Yes | |
| ucs2_polish_ci | ucs2 | | | Yes | |
| ucs2_estonian_ci | ucs2 | | | Yes | |
| ucs2_spanish_ci | ucs2 | | | Yes | |
| ucs2_swedish_ci | ucs2 | | | Yes | |
| ucs2_turkish_ci | ucs2 | | | Yes | |
| ucs2_czech_ci | ucs2 | | | Yes | |
| ucs2_danish_ci | ucs2 | | | Yes | |
| ucs2_lithuanian_ci | ucs2 | | | Yes | |
| ucs2_slovak_ci | ucs2 | | | Yes | |
| ucs2_spanish2_ci | ucs2 | | | Yes | |
| ucs2_roman_ci | ucs2 | | | Yes | |
| ucs2_persian_ci | ucs2 | | | Yes | |
| ucs2_esperanto_ci | ucs2 | | | Yes | |
| ucs2_hungarian_ci | ucs2 | | | Yes | |
| ucs2_sinhala_ci | ucs2 | | | Yes | |
| ucs2_german2_ci | ucs2 | | | Yes | |
| ucs2_croatian_ci | ucs2 | | | Yes | |
| ucs2_unicode_520_ci | ucs2 | | | Yes | |
| ucs2_vietnamese_ci | ucs2 | | | Yes | |
| ucs2_general_mysql500_ci | ucs2 | | | Yes | |
| cp866_general_ci | cp866 | | Yes | Yes | |
| cp866_bin | cp866 | | | Yes | |
| keybcs2_general_ci | keybcs2 | | Yes | Yes | |
| keybcs2_bin | keybcs2 | | | Yes | |
| macce_general_ci | macce | | Yes | Yes | |
| macce_bin | macce | | | Yes | |
| macroman_general_ci | macroman | | Yes | Yes | |
| macroman_bin | macroman | | | Yes | |
| cp852_general_ci | cp852 | | Yes | Yes | |
| cp852_bin | cp852 | | | Yes | |
| latin7_estonian_cs | latin7 | | | Yes | |
| latin7_general_ci | latin7 | | Yes | Yes | |
| latin7_general_cs | latin7 | | | Yes | |
| latin7_bin | latin7 | | | Yes | |
| utf8mb4_general_ci | utf8mb4 | | Yes | Yes | |
| utf8mb4_bin | utf8mb4 | | | Yes | |
| utf8mb4_unicode_ci | utf8mb4 | | | Yes | |
| utf8mb4_icelandic_ci | utf8mb4 | | | Yes | |
| utf8mb4_latvian_ci | utf8mb4 | | | Yes | |
| utf8mb4_romanian_ci | utf8mb4 | | | Yes | |
| utf8mb4_slovenian_ci | utf8mb4 | | | Yes | |
| utf8mb4_polish_ci | utf8mb4 | | | Yes | |
| utf8mb4_estonian_ci | utf8mb4 | | | Yes | |
| utf8mb4_spanish_ci | utf8mb4 | | | Yes | |
| utf8mb4_swedish_ci | utf8mb4 | | | Yes | |
| utf8mb4_turkish_ci | utf8mb4 | | | Yes | |
| utf8mb4_czech_ci | utf8mb4 | | | Yes | |
| utf8mb4_danish_ci | utf8mb4 | | | Yes | |
| utf8mb4_lithuanian_ci | utf8mb4 | | | Yes | |
| utf8mb4_slovak_ci | utf8mb4 | | | Yes | |
| utf8mb4_spanish2_ci | utf8mb4 | | | Yes | |
| utf8mb4_roman_ci | utf8mb4 | | | Yes | |
| utf8mb4_persian_ci | utf8mb4 | | | Yes | |
| utf8mb4_esperanto_ci | utf8mb4 | | | Yes | |
| utf8mb4_hungarian_ci | utf8mb4 | | | Yes | |
| utf8mb4_sinhala_ci | utf8mb4 | | | Yes | |
| utf8mb4_german2_ci | utf8mb4 | | | Yes | |
| utf8mb4_croatian_ci | utf8mb4 | | | Yes | |
| utf8mb4_unicode_520_ci | utf8mb4 | | | Yes | |
| utf8mb4_vietnamese_ci | utf8mb4 | | | Yes | |
| cp1251_bulgarian_ci | cp1251 | | | Yes | |
| cp1251_ukrainian_ci | cp1251 | | | Yes | |
| cp1251_bin | cp1251 | | | Yes | |
| cp1251_general_ci | cp1251 | | Yes | Yes | |
| cp1251_general_cs | cp1251 | | | Yes | |
| utf16_general_ci | utf16 | | Yes | Yes | |
| utf16_bin | utf16 | | | Yes | |
| utf16_unicode_ci | utf16 | | | Yes | |
| utf16_icelandic_ci | utf16 | | | Yes | |
| utf16_latvian_ci | utf16 | | | Yes | |
| utf16_romanian_ci | utf16 | | | Yes | |
| utf16_slovenian_ci | utf16 | | | Yes | |
| utf16_polish_ci | utf16 | | | Yes | |
| utf16_estonian_ci | utf16 | | | Yes | |
| utf16_spanish_ci | utf16 | | | Yes | |
| utf16_swedish_ci | utf16 | | | Yes | |
| utf16_turkish_ci | utf16 | | | Yes | |
| utf16_czech_ci | utf16 | | | Yes | |
| utf16_danish_ci | utf16 | | | Yes | |
| utf16_lithuanian_ci | utf16 | | | Yes | |
| utf16_slovak_ci | utf16 | | | Yes | |
| utf16_spanish2_ci | utf16 | | | Yes | |
| utf16_roman_ci | utf16 | | | Yes | |
| utf16_persian_ci | utf16 | | | Yes | |
| utf16_esperanto_ci | utf16 | | | Yes | |
| utf16_hungarian_ci | utf16 | | | Yes | |
| utf16_sinhala_ci | utf16 | | | Yes | |
| utf16_german2_ci | utf16 | | | Yes | |
| utf16_croatian_ci | utf16 | | | Yes | |
| utf16_unicode_520_ci | utf16 | | | Yes | |
| utf16_vietnamese_ci | utf16 | | | Yes | |
| utf16le_general_ci | utf16le | | Yes | Yes | |
| utf16le_bin | utf16le | | | Yes | |
| cp1256_general_ci | cp1256 | | Yes | Yes | |
| cp1256_bin | cp1256 | | | Yes | |
| cp1257_lithuanian_ci | cp1257 | | | Yes | |
| cp1257_bin | cp1257 | | | Yes | |
| cp1257_general_ci | cp1257 | | Yes | Yes | |
| utf32_general_ci | utf32 | | Yes | Yes | |
| utf32_bin | utf32 | | | Yes | |
| utf32_unicode_ci | utf32 | | | Yes | |
| utf32_icelandic_ci | utf32 | | | Yes | |
| utf32_latvian_ci | utf32 | | | Yes | |
| utf32_romanian_ci | utf32 | | | Yes | |
| utf32_slovenian_ci | utf32 | | | Yes | |
| utf32_polish_ci | utf32 | | | Yes | |
| utf32_estonian_ci | utf32 | | | Yes | |
| utf32_spanish_ci | utf32 | | | Yes | |
| utf32_swedish_ci | utf32 | | | Yes | |
| utf32_turkish_ci | utf32 | | | Yes | |
| utf32_czech_ci | utf32 | | | Yes | |
| utf32_danish_ci | utf32 | | | Yes | |
| utf32_lithuanian_ci | utf32 | | | Yes | |
| utf32_slovak_ci | utf32 | | | Yes | |
| utf32_spanish2_ci | utf32 | | | Yes | |
| utf32_roman_ci | utf32 | | | Yes | |
| utf32_persian_ci | utf32 | | | Yes | |
| utf32_esperanto_ci | utf32 | | | Yes | |
| utf32_hungarian_ci | utf32 | | | Yes | |
| utf32_sinhala_ci | utf32 | | | Yes | |
| utf32_german2_ci | utf32 | | | Yes | |
| utf32_croatian_ci | utf32 | | | Yes | |
| utf32_unicode_520_ci | utf32 | | | Yes | |
| utf32_vietnamese_ci | utf32 | | | Yes | |
| binary | binary | | Yes | Yes | |
| geostd8_general_ci | geostd8 | | Yes | Yes | |
| geostd8_bin | geostd8 | | | Yes | |
| cp932_japanese_ci | cp932 | | Yes | Yes | |
| cp932_bin | cp932 | | | Yes | |
| eucjpms_japanese_ci | eucjpms | | Yes | Yes | |
| eucjpms_bin | eucjpms | | | Yes | |
+--------------------------+--------------------+-----+------------+-------------+---------+
rows in set (0.02 sec)
Instead of manually comparing each row, you can calculate a checksum and only compare the checksum:
mysql> pager md5sum;
PAGER set to 'md5sum'
mysql> select * from COLLATIONS;
6650d5d87f2abe18b6ead3588b133087 -
rows in set (0.02 sec)
mysql> pager md5sum
PAGER set to 'md5sum' # Original query
mysql> SELECT ...
32a1894d773c9b85172969c659175d2d -
row in set (0.40 sec) # Rewritten query - wrong
mysql> SELECT ...
fdb94521558684afedc8148ca724f578 -
row in set (0.16 sec)
Hmmm, checksums don’t match, something is wrong. Let’s retry:
# Rewritten query - correct
mysql> SELECT ...
32a1894d773c9b85172969c659175d2d -
row in set (0.17 sec)
Checksums are identical, the rewritten query is much likely to produce the same result as the original one.
Cleaning up SHOW PROCESSLIST
If you have lots of connections on your MySQL, it’s very difficult to read the output of SHOW PROCESSLIST
. For instance, if you have several hundreds of connections and you want to know how many connections are sleeping, manually counting the rows from the output of SHOW PROCESSLIST
is probably not the best solution. With pager, it is straightforward:
mysql> show processlist;
+----+------+-----------+--------------------+---------+------+-------+------------------+
| Id | User | Host | db | Command | Time | State | Info |
+----+------+-----------+--------------------+---------+------+-------+------------------+
| | root | localhost | information_schema | Query | | init | show processlist |
| | root | localhost | test | Sleep | | | NULL |
+----+------+-----------+--------------------+---------+------+-------+------------------+
rows in set (0.00 sec) mysql> pager grep Sleep |wc -l
PAGER set to 'grep Sleep |wc -l' mysql> show processlist; rows in set (0.00 sec)
Slightly more complicated now: you want to know the number of connections for each status:
mysql> pager awk -F '|' '{print $6}' | sort | uniq -c | sort -r
PAGER set to 'awk -F '|' '{print $}' | sort | uniq -c | sort -r'
mysql> show processlist; Sleep
Query
Command
rows in set (0.00 sec)
Astute readers will have noticed that these questions could have been solved by querying INFORMATION_SCHEMA. For instance, counting the number of sleeping connections can be done with:
mysql> SELECT COUNT(*) FROM INFORMATION_SCHEMA.PROCESSLIST WHERE COMMAND='Sleep';
+----------+
| COUNT(*) |
+----------+
| 1 |
+----------+
1 row in set (0.17 sec)
and counting the number of connection for each status can be done with:
mysql> SELECT COMMAND,COUNT(*) TOTAL FROM INFORMATION_SCHEMA.PROCESSLIST GROUP BY COMMAND ORDER BY TOTAL DESC;
+---------+-------+
| COMMAND | TOTAL |
+---------+-------+
| Query | |
| Sleep | |
+---------+-------+
rows in set (0.01 sec)
True, but:
- It’s nice to know several ways to get the same result
- Some of you may feel more comfortable with writing SQL queries, while others will prefer command line tools
pager 命令的更多相关文章
- mysql中pager命令妙用
pager命令的妙用在mysql,可以大大提高工作效率. 一 当处理大量数据时,不想显示查询的结果,而只需知道查询话费的时间. mysql> select * from t3; +----- ...
- 介绍一些有趣的MySQL pager命令
一.分页结果集 在Linux系统中中,我们经常也会使用一些分页查看命令,例如less.more等.同样,MySQL客户端也提供了类似的命令,用来帮助我们对查询结果集进行分页.比如,SHOW ENGIN ...
- mysql pager用法&命令行命令
下面讲的命令,有部分只能在linux上才有.像pager命令windows上就没有了. 分屏:在Linux上,而且不是xwindow时,使用mysql命令行时,输出太多的东西,看不到就很悲剧了.在sh ...
- mysql的一些特殊命令
mysql命令行工具的编辑技巧 从mysql performace blog 中学到的: 1. pager 例子 mysql> pager more PAGER set to 'more' my ...
- Mysql 客户端查询结果如何保存到本地而不是服务端?
应用场景:知道某台DB服务器的IP和账户,登录上去查询了10W条记录,需要把这些记录拉到本地做分析 方法1,远程连接到DB服务器执行OUTFILE命令,文件存储在DB机器上,只有mysql账户的情况下 ...
- MySQL 实用技巧
概述: MySQL有许多实用的技巧,利用这些技巧能提高工作的效率,减少一些不必要的麻烦.以下是几个我在MySQL日常维护从常用的技巧. 一.prompt 命令 功能:设置mysql客户端提示符 说明: ...
- 【Linux】使用update-alternatives命令进行版本的切换
引言 在Redhat中也有此功能,用于切换不同版本. 在Debian系统中,我们可能会同时安装有很多功能类似的程序和可选配置,可能会出现同一软件的多个版本并存的场景.比如像是一些编程语言工具,一些系统 ...
- 十个节省时间的MySQL命令
十个节省时间的MySQL命令 2011-02-23 16:07 黄永兵 译 IT168 字号:T | T 编者在工作中积累起来了一些MySQL命令行客户端技巧,这些技巧或多或少会帮助您节省大量的时间. ...
- [Android ] linux命令英文缩写的含义(方便记忆)
du -sh */ reference to : http://blog.chinaunix.net/uid-27164517-id-3299073.html linux常用命令的英文单词缩写 命令缩 ...
随机推荐
- Calling C++ code from C# z
http://blogs.msdn.com/b/borisj/archive/2006/09/28/769708.aspx I apologize for the long delay for thi ...
- C++实现网格水印之调试笔记(五)—— 提取出错
在实现提取水印的过程中,遇到了一些问题 首先还是根据论文中的思路来梳理一下整个提取流程 读入两个模型,一个原始模型ori_mesh, 一个水印模型wm_mesh. 将两个模型对齐(即放在同一个坐标系下 ...
- 你是怎么理解“MVC”的
MVC就是三个字母的组合,M-模型, V-视图, C-控制器. 这些在百度上随便一索就可以索到,而且网上对这三个部分的解释又过于笼统,使人没法完全理解MVC的含义. 这里我简单的谈谈我对MVC这三 ...
- Annotations:注解
注解,作为元数据的一种形式,虽不是程序的一部分,却有以下作用: 可以让编译器跳过某些检测 某些工具可以根据注解信息生成文档等 某些注解可以在运行时检查 @表示这是一个注解 @Override ...
- 【VB技巧】VB静态调用与动态调用dll详解
本文“[VB技巧]VB静态调用与动态调用dll详解”,来自:Nuclear'Atk 网络安全研究中心,本文地址:http://lcx.cc/?i=489,转载请注明作者及出处! [[请注意]]:在以下 ...
- mysql performance_schema 初探
mysql performance_schema 初探: mysql 5.5 版本 新增了一个性能优化的引擎: PERFORMANCE_SCHEMA 这个功能默认是关闭的: 需要设置参数: perf ...
- 第二百四十四、五天 how can I 坚持
昨天忘了.不知咋忘的,加班加迷糊了? 昨天联调接口,又加班了,好歹基本调通了. 今天,下午,开会,有点被领导批的意思,不是批我,是批我们团队. 团队. 不懂自己. 这样做有意义嘛. 睡觉.好烦. 到底 ...
- 【转】Maven实战(八)---模块划分
本博文出自于:http://blog.csdn.net/liutengteng130/article/details/47000217 感谢! 为了防止传递依赖,我们各个模块之间尽量用直接依赖的 ...
- 软件工程 --- Pair Project: Elevator Scheduler [电梯调度算法的实现和测试] [附加题]
软件工程 --- Pair Project: Elevator Scheduler [电梯调度算法的实现和测试] [附加题] 首先,在分组之前,我和室友薛亚杰已经详细阅读了往届学长的博客,认为电梯调度 ...
- Web开发人员需知的Web缓存知识
最近的译文距今已有4年之久,原文有一定的更新.今天踩着前辈们的肩膀,再次把这篇文章翻译整理下.一来让自己对web缓存的理解更深刻些,二来让大家注意力稍稍转移下,不要整天HTML5, 面试题啊叨啊叨的~ ...