您的位置:首页 > 数据库 > Oracle

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

2015-11-17 18:12 786 查看
在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)
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: