1 TEE 命令说明
在Oracle 的SQLPLUS 工具中我们可以执行spool来记录操作内容,在MySQL中,可以使用tee工具来实现。
Linux tee 命令用于读取标准输入的数据,并将其内容输出成文件。tee 指令会从标准输入设备读取数据,将其内容输出到标准输出设备,同时保存成文件。
命令帮助:
[dave@www.cndba.cn:~]# tee --help
用法:tee [选项]... [文件]...
将标准输入复制到每个指定文件,并显示到标准输出。
-a, --append 内容追加到给定的文件而非覆盖
-i, --ignore-interrupts 忽略中断信号
--help 显示此帮助信息并退出
--version 显示版本信息并退出
2 MySQL中使用tee
2.1 在连接时使用
[dave@www.cndba.cn:~]# /data1/mysql/3308/app/bin/mysql -uroot --tee=/tmp/tee.txt -S /data1/mysql/3308/run/mysqld.sock -p
Logging to file '/tmp/tee.txt'
Enter password:
Welcome to the MySQL monitor. Commands end with ; or /g.
Your MySQL connection id is 19
Server version: 5.7.25-log MySQL Community Server (GPL)
Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '/h' for help. Type '/c' to clear the current input statement.
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| cndba |
| mysql |
| performance_schema |
| sys |
| ustc |
+--------------------+
6 rows in set (0.00 sec)
mysql> exit
Bye
查看tee文件内容:
[dave@www.cndba.cn:~]# cat /tmp/tee.txt
Welcome to the MySQL monitor. Commands end with ; or /g.
Your MySQL connection id is 19
Server version: 5.7.25-log MySQL Community Server (GPL)
Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '/h' for help. Type '/c' to clear the current input statement.
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| cndba |
| mysql |
| performance_schema |
| sys |
| ustc |
+--------------------+
6 rows in set (0.00 sec)
mysql> exit
[dave@www.cndba.cn:~]#
2.2 连接后使用
[dave@www.cndba.cn:~]# mysql_conn 3308
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor. Commands end with ; or /g.
Your MySQL connection id is 20
Server version: 5.7.25-log MySQL Community Server (GPL)
Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '/h' for help. Type '/c' to clear the current input statement.
启用tee:
mysql> tee /tmp/tee2.txt
Logging to file '/tmp/tee2.txt'
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| cndba |
| mysql |
| performance_schema |
| sys |
| ustc |
+--------------------+
6 rows in set (0.00 sec)
退出tee:
mysql> notee
Outfile disabled.
mysql> exit
Bye
查看tee 文件:
[dave@www.cndba.cn:~]# cat /tmp/tee2.txt
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| cndba |
| mysql |
| performance_schema |
| sys |
| ustc |
+--------------------+
6 rows in set (0.00 sec)
mysql> notee
[dave@www.cndba.cn:~]#
版权声明:本文为博主原创文章,未经博主允许不得转载。