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

原创 2015年11月17日 18:12:45

  在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)


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

相关文章推荐

用mysql实现类似于oracle dblink的功能

用mysql实现类似于oracle dblink的功能  首先看看有没有federated 引擎。  mysql> show engines;  +------------+----------...

用mysql实现类似于oracle dblink的功能

用mysql实现类似于oracle dblink的功能  首先看看有没有federated 引擎。  mysql> show engines;  +------------+----------...

MySQL实现类似Oracle中start with功能

原文链接:http://www.jb51.net/article/48407.htm CREATE FUNCTION `getChildList`(rootId INT) RETURNS varch...

使用spool工具导出oracle文本数据

1、win下批处理调度文件 data_spool.bat F:\oracle\product\10.2.0\db_1\BIN\sqlplus tax/tax@orcl @D:\PDM_SQL\sp...

使用spool工具导出oracle文本数据

1、win下批处理调度文件 data_spool.bat [sql] view plaincopy F:\oracle\product\10.2.0\db...

MYSQL tee的功能测试

Mysql将结果保存到文件,从文件中执行sql语句记录操作过程(tee命令的使用) 1. 有时候我们可能需要记录用户对mysql的操作过程,这时我们可以使用mysql的tee命令 1)第一...

Oracle中spool命令实现的两种方法比较

http://www.linuxidc.com/Linux/2009-04/19576.htm 要输出符合要求格式的数据文件只需在select时用字符连接来规范格式。比如有如下表 SQ...

SPOOL 命令使用实例【oracle导出纯文本格式文件】

SPOOL 命令使用实例【oracle导出纯文本格式文件】 上一篇 / 下一篇  2012-03-15 12:36:11 / 个人分类:ORACLE工具 查看( 938 ) / 评论( 0...

Oracle使用spool命令导出文本文件

一、基本命令介绍1、文本格式设置命令 命令参数 描述 SET echo off 在用start命令执行一个sql脚本时,是否显示脚本中正在执行的SQL语句; SET feedback...
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:mysql中使用tee实现类似oracle spool功能
举报原因:
原因补充:

(最多只允许输入30个字)