MySQL之高级命令使用介绍,mysql命令


一、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)]>

相关内容