一, MySQL 之高级命令 Pager 使用
分屏显示内容:
- root@localhost [(none)]>pager more
- PAGER set to 'more'
- root@localhost [(none)]>select * from testdb.zx_scores;
- root@localhost [(none)]>pager Less
- PAGER set to 'less'
- root@localhost [(none)]>
- root@localhost [(none)]>select * from testdb.zx_scores;
结果中搜索:
- root@localhost [(none)]>pager grep Sleep|wc -l;
- PAGER set to 'grep Sleep|wc -l'
- root@localhost [(none)]>show full processlist;
- 0
- 7 rows in set (0.00 sec)
- root@localhost [(none)]>
不显示查询出来结果:
- root@localhost [(none)]>pager cat>>/dev/null
- PAGER set to 'cat>>/dev/null'
- root@localhost [(none)]>select * from information_schema.tables;
- 282 rows in set, 48 warnings (0.04 sec)
- root@localhost [(none)]>select * from testdb.zx_scores;
- 33 rows in set (0.01 sec)
- root@localhost [(none)]>nopager
- PAGER set to stdout
- root@localhost [(none)]>select count(*) from testdb.zx_scores;
- +----------+
- | count(*) |
- +----------+
- | 33 |
- +----------+
- 1 row in set (0.00 sec)
结果用 md5sum 比较:
- root@localhost [(none)]>pager md5sum
- PAGER set to 'md5sum'
- root@localhost [(none)]>select * from information_schema.tables;
- f3e004ca08069e1b4536d175f8373583 -
- 282 rows in set, 48 warnings (0.05 sec)
恢复 pager:
root@localhost [(none)]>pager 或是 root@localhost [(none)]>nopager
二, 记录 MySQL 输入的命令及结果
使用 tee 命令或是在配置文件配置, 演示如下:
- root@localhost [(none)]>tee /tmp/MySQL.log
- Logging to file '/tmp/mysql.log'
- root@localhost [(none)]>select count(*) from testdb.zx_scores;
- +----------+
- | count(*) |
- +----------+
- | 33 |
- +----------+
- 1 row in set (0.00 sec)
- [root@localhost ~]# tailf /tmp/MySQL.log
- root@localhost [(none)]>select count(*) from testdb.zx_scores;
- +----------+
- | count(*) |
- +----------+
- | 33 |
- +----------+
- 1 row in set (0.00 sec)
- root@localhost [(none)]>select count(*) from testdb.zx_scores;
- +----------+
- | count(*) |
- +----------+
- | 33 |
- +----------+
- 1 row in set (0.00 sec)
另外也可以通过在配置文件中, 加如下这个配置 :
- [MySQL]
- tee=/tmp/MySQL.log
再次登录即可 (前提这个配置文件是可以被 MySQL 读到的)
三, MySQL 调用系统命令
该功能只能 Linux 平台支持, 利用 system 后面跟命令调用
- root@localhost [(none)]>system ls
- root@localhost [(none)]>system top
- root@localhost [(none)]>system ps -eostart,cmd,pid|grep mysqld
- Nov 26 /usr/local/MySQL/bin/mysqld 2798
- 18:06:15 grep mysqld 9247
- root@localhost [(none)]>
- root@localhost [(none)]>system ps -ef|grep mysqld
root 1023 1 0 11 月 26 ? 00:00:00 /bin/sh /usr/local/MySQL//bin/mysqld_safe --datadir=/data/MySQL/data --pid-file=/data/MySQL/data/localhost.localdomain.pid
MySQL 2798 1023 0 11 月 26 ? 00:07:41 /usr/local/MySQL/bin/mysqld --basedir=/usr/local/MySQL/ --datadir=/data/MySQL/data --plugin-dir=/usr/local/MySQL//lib/plugin --user=MySQL --log-error=/data/MySQL/logs/error.log --open-files-limit=65536 --pid-file=/data/MySQL/data/localhost.localdomain.pid --socket=/tmp/MySQL.sock --port=3306
- root 9248 9194 0 18:06 pts/0 00:00:00 sh -c ps -ef|grep mysqld
- root 9250 9248 0 18:06 pts/0 00:00:00 grep mysqld
- root@localhost [(none)]>
欢迎大家一起交流学习, 如果有其他的高级的命令, 希望大家可以分享下, 一起探讨, 共同进步
来源: http://www.bubuko.com/infodetail-2872943.html