签到成功

知道了

CNDBA社区CNDBA社区

MySQL tee 命令 说明

2023-10-08 13:31 435 0 原创 MySQL
作者: dave

1 TEE 命令说明

在Oracle 的SQLPLUS 工具中我们可以执行spool来记录操作内容,在MySQL中,可以使用tee工具来实现。
Linux tee 命令用于读取标准输入的数据,并将其内容输出成文件。tee 指令会从标准输入设备读取数据,将其内容输出到标准输出设备,同时保存成文件。http://www.cndba.cn/dave/article/131452

命令帮助:http://www.cndba.cn/dave/article/131452http://www.cndba.cn/dave/article/131452

[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文件内容:http://www.cndba.cn/dave/article/131452

http://www.cndba.cn/dave/article/131452
http://www.cndba.cn/dave/article/131452
http://www.cndba.cn/dave/article/131452http://www.cndba.cn/dave/article/131452

[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 文件:http://www.cndba.cn/dave/article/131452http://www.cndba.cn/dave/article/131452

[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:~]#

版权声明:本文为博主原创文章,未经博主允许不得转载。

用户评论
* 以下用户言论只代表其个人观点,不代表CNDBA社区的观点或立场
dave

dave

关注

人的一生应该是这样度过的:当他回首往事的时候,他不会因为虚度年华而悔恨,也不会因为碌碌无为而羞耻;这样,在临死的时候,他就能够说:“我的整个生命和全部精力,都已经献给世界上最壮丽的事业....."

  • 2237
    原创
  • 2
    翻译
  • 535
    转载
  • 185
    评论
  • 访问:6531570次
  • 积分:4229
  • 等级:核心会员
  • 排名:第1名
精华文章
    最新问题
    查看更多+
    热门文章
      热门用户
      推荐用户
        Copyright © 2016 All Rights Reserved. Powered by CNDBA · 皖ICP备2022006297号-1·

        QQ交流群

        注册联系QQ