关闭

mysql中使用tee实现类似oracle spool功能

标签: mysql teeteeoracle spool
394人阅读 评论(0) 收藏 举报
分类:

  在mysql中我们可以通过tee来实现类似oracle 中spool的功能,实现方式有如下三种:

1.在/etc/my.cnf中的[client]部分加入类似如下内容

tee =/root/tee.log

##这样在新的客户端登录数据库时就会记录他所有的操作

 mysql -uroot -p -S /tmp/mysql3306.sock
Logging to file '/root/tee.log' <span style="color:#ff0000;"> >>已经生成了日志</span>
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.6.27-log Source distribution

Copyright (c) 2000, 2015, 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;操作后查看tee.log

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| shao               |
| test               |
+--------------------+
5 rows in set (0.00 sec)

vi /root/tee.log

vi /root/tee.log
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.6.27-log Source distribution

Copyright (c) 2000, 2015, 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 |
| mysql              |
| performance_schema |
| shao               |
| test               |
+--------------------+
5 rows in set (0.00 sec)

2.在登录的时候指定--tee参数

mysql -uroot -p -S /tmp/mysql3306.sock --tee=/root/tee.log
Logging to file '/root/tee.log'  <span style="color:#ff0000;">>>生成日志</span>
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 4
Server version: 5.6.27-log Source distribution

Copyright (c) 2000, 2015, 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 |
| mysql              |
| performance_schema |
| shao               |
| test               |
+--------------------+
5 rows in set (0.00 sec)

3.登录mysql后执行tee命令

mysql> tee /root/tee.log
Logging to file '/root/tee.log'
mysql> show variables like 'port';
+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| port          | 3306  |
+---------------+-------+
1 row in set (0.00 sec)

mysql> 
查看日志
 vi tee.log 
mysql> show variables like 'port';
+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| port          | 3306  |
+---------------+-------+
1 row in set (0.00 sec)


0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:260712次
    • 积分:4916
    • 等级:
    • 排名:第5979名
    • 原创:178篇
    • 转载:137篇
    • 译文:43篇
    • 评论:5条
    文章分类
    最新评论