1. 程式人生 > >MySQL之高階命令使用介紹

MySQL之高階命令使用介紹

一、mysql之高階命令Pager使用

分屏顯示內容:

[email protected] [(none)]>pager more
PAGER set to 'more'
[email protected] [(none)]>select * from testdb.zx_scores;

[email protected] [(none)]>pager less
PAGER set to 'less'
[email protected] [(none)]>
[email protected] [(none)]>select * from testdb.zx_scores;

結果中搜索:

[email protected] [(none)]>pager grep  Sleep|wc -l;
PAGER set to 'grep  Sleep|wc -l'
[email protected] [(none)]>show full processlist;
0
7 rows in set (0.00 sec)

[email protected] [(none)]>

不顯示查詢出來結果:

[email protected] [(none)]>pager cat >>/dev/null
PAGER set to 'cat >>/dev/null'
[email protected]
[(none)]>select * from information_schema.tables; 282 rows in set, 48 warnings (0.04 sec) [email protected] [(none)]>select * from testdb.zx_scores; 33 rows in set (0.01 sec) [email protected] [(none)]>nopager PAGER set to stdout [email protected] [(none)]>select count(*) from testdb.zx_scores; +----------+ | count(*) | +----------+ | 33 | +----------+ 1 row in set (0.00 sec)

結果用md5sum比較:

[email protected] [(none)]>pager md5sum
PAGER set to 'md5sum'
[email protected] [(none)]>select * from information_schema.tables;
f3e004ca08069e1b4536d175f8373583  -
282 rows in set, 48 warnings (0.05 sec)

恢復 pager:

[email protected] [(none)]>pager 或是 [email protected] [(none)]>nopager

二、記錄MySQL輸入的命令及結果

使用tee命令或是在配置檔案配置,演示如下:


[email protected] [(none)]>tee /tmp/mysql.log
Logging to file '/tmp/mysql.log'
[email protected] [(none)]>select count(*) from testdb.zx_scores;
+----------+
| count(*) |
+----------+
|       33 |
+----------+
1 row in set (0.00 sec)
[[email protected] ~]# tailf  /tmp/mysql.log
[email protected] [(none)]>select count(*) from testdb.zx_scores;
+----------+
| count(*) |
+----------+
|       33 |
+----------+
1 row in set (0.00 sec)
[email protected] [(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後面跟命令呼叫

[email protected] [(none)]>system ls

[email protected] [(none)]>system top

[email protected] [(none)]>system ps -eostart,cmd,pid|grep mysqld
  Nov 26 /usr/local/mysql/bin/mysqld  2798
18:06:15 grep mysqld                  9247
[email protected] [(none)]>

[email protected] [(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
[email protected] [(none)]>

歡迎大家一起交流學習,如果有其他的高階的命令,希望大家可以分享下,一起探討,共同進步