mysql tee_MySQL 使用tee记录语句和输出日志
在mysql命令行中,使用tee命令,可以记录语句和输出到指定文件。在debugging时会很有用。
每执行一条语句,mysql都会讲执行结果刷新到指定文件。Tee功能只在交互模式生效。
mysql> tee /tmp/20160908.log
Logging to file '/tmp/20160908.log'
mysql> show databases;
ERROR 2006 (HY000): MySQL server has gone away
No connection. Trying to reconnect...
Connection id: 4
Current database: test
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| test |
+--------------------+
4 rows in set (0.01 sec)
mysql> use test
Database changed
mysql> show tables;
+--------------------+
| Tables_in_test |
+--------------------+
| ADDSubscribers |
| Subscribers |
| dept |
| emp |
| t10 |
| t2 |
| t5 |
| t50 |
| t7 |
| test |
| tmp_Subscribers_01 |
| tmp_Subscribers_02 |
| tmp_Subscribers_03 |
| version |
+--------------------+
14 rows in set (0.00 sec)
mysql> select * from emp;
+-------+--------+-----------+------+---------------------+------+------+--------+
| empno | ename | job | mgr | hiredate | sal | com | deptno |
+-------+--------+-----------+------+---------------------+------+------+--------+
| 7369 | SMITH | CLERK | 7902 | 1980-12-17 00:00:00 | 800 | NULL | 20 |
| 7499 | ALLEN | SALESMAN | 7698 | 1981-02-20 00:00:00 | 1600 | 300 | 30 |
| 7521 | WARD | SALESMAN | 7698 | 1981-02-22 00:00:00 | 1250 | 500 | 30 |
| 7566 | JONES | MANAGER | 7839 | 1981-04-02 00:00:00 | 2975 | NULL | 20 |
| 7654 | MARTIN | SALESMAN | 7698 | 1981-09-28 00:00:00 | 1250 | 1400 | 30 |
| 7698 | BLAKE | MANAGER | 7839 | 1981-05-01 00:00:00 | 2850 | NULL | 30 |
| 7782 | CLARK | MANAGER | 7839 | 1981-06-09 00:00:00 | 2450 | NULL | 10 |
| 7788 | SCOTT | ANALYST | 7566 | 1987-07-13 00:00:00 | 3000 | NULL | 20 |
| 7839 | KING | PRESIDENT | NULL | 1981-11-17 00:00:00 | 5000 | NULL | 10 |
| 7844 | TURNER | SALESMAN | 7698 | 1981-09-08 00:00:00 | 1500 | 0 | 30 |
| 7876 | ADAMS | CLERK | 7788 | 1987-07-13 00:00:00 | 1100 | NULL | 20 |
| 7900 | JAMES | CLERK | 7698 | 1981-12-03 00:00:00 | 950 | NULL | 30 |
| 7902 | FORD | ANALYST | 7566 | 1981-12-03 00:00:00 | 3000 | NULL | 20 |
| 7934 | MILLER | CLERK | 7782 | 1982-01-23 00:00:00 | 1300 | NULL | 10 |
+-------+--------+-----------+------+---------------------+------+------+--------+
14 rows in set (0.03 sec)
使用notee命令来关闭日志记录
mysql> notee
Outfile disabled.
查看生成的日志
[root@localhost fire]# cat /tmp/20160908.log
mysql> show databases;
ERROR 2006 (HY000): MySQL server has gone away
No connection. Trying to reconnect...
Connection id: 4
Current database: test
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| test |
+--------------------+
4 rows in set (0.01 sec)
mysql> use test
Database changed
mysql> show tables;
+--------------------+
| Tables_in_test |
+--------------------+
| ADDSubscribers |
| Subscribers |
| dept |
| emp |
| t10 |
| t2 |
| t5 |
| t50 |
| t7 |
| test |
| tmp_Subscribers_01 |
| tmp_Subscribers_02 |
| tmp_Subscribers_03 |
| version |
+--------------------+
14 rows in set (0.00 sec)
mysql> select * from emp;
+-------+--------+-----------+------+---------------------+------+------+--------+
| empno | ename | job | mgr | hiredate | sal | com | deptno |
+-------+--------+-----------+------+---------------------+------+------+--------+
| 7369 | SMITH | CLERK | 7902 | 1980-12-17 00:00:00 | 800 | NULL | 20 |
| 7499 | ALLEN | SALESMAN | 7698 | 1981-02-20 00:00:00 | 1600 | 300 | 30 |
| 7521 | WARD | SALESMAN | 7698 | 1981-02-22 00:00:00 | 1250 | 500 | 30 |
| 7566 | JONES | MANAGER | 7839 | 1981-04-02 00:00:00 | 2975 | NULL | 20 |
| 7654 | MARTIN | SALESMAN | 7698 | 1981-09-28 00:00:00 | 1250 | 1400 | 30 |
| 7698 | BLAKE | MANAGER | 7839 | 1981-05-01 00:00:00 | 2850 | NULL | 30 |
| 7782 | CLARK | MANAGER | 7839 | 1981-06-09 00:00:00 | 2450 | NULL | 10 |
| 7788 | SCOTT | ANALYST | 7566 | 1987-07-13 00:00:00 | 3000 | NULL | 20 |
| 7839 | KING | PRESIDENT | NULL | 1981-11-17 00:00:00 | 5000 | NULL | 10 |
| 7844 | TURNER | SALESMAN | 7698 | 1981-09-08 00:00:00 | 1500 | 0 | 30 |
| 7876 | ADAMS | CLERK | 7788 | 1987-07-13 00:00:00 | 1100 | NULL | 20 |
| 7900 | JAMES | CLERK | 7698 | 1981-12-03 00:00:00 | 950 | NULL | 30 |
| 7902 | FORD | ANALYST | 7566 | 1981-12-03 00:00:00 | 3000 | NULL | 20 |
| 7934 | MILLER | CLERK | 7782 | 1982-01-23 00:00:00 | 1300 | NULL | 10 |
+-------+--------+-----------+------+---------------------+------+------+--------+
14 rows in set (0.03 sec)
mysql> notee
当调用mysql时,使用--tee参数,可以记录这个登录会话的全部日志。
[root@localhost ~]# mysql -uroot -p --tee=/tmp/20160908_02.log
Logging to file '/tmp/20160908_02.log'
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 5
Server version: 5.6.31-77.0-log Percona Server (GPL), Release 77.0, Revision 5c1061c
Copyright (c) 2009-2016 Percona LLC and/or its affiliates
Copyright (c) 2000, 2016, 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> use test
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
mysql> select * from test;
+------+-------+
| id | name |
+------+-------+
| 10 | neo |
| 20 | John |
| 30 | Lucy |
| 40 | Larry |
| 50 | Lilly |
+------+-------+
5 rows in set (0.04 sec)查看生成的日志
[root@localhost fire]# cat /tmp/20160908_02.log
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 5
Server version: 5.6.31-77.0-log Percona Server (GPL), Release 77.0, Revision 5c1061c
Copyright (c) 2009-2016 Percona LLC and/or its affiliates
Copyright (c) 2000, 2016, 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> use test
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
mysql> select * from test;
+------+-------+
| id | name |
+------+-------+
| 10 | neo |
| 20 | John |
| 30 | Lucy |
| 40 | Larry |
| 50 | Lilly |
+------+-------+
5 rows in set (0.04 sec)
mysql tee_MySQL 使用tee记录语句和输出日志相关推荐
- 学习笔记(03):MySQL数据库运维与管理-01-mysql通用日志与错误日志
立即学习:https://edu.csdn.net/course/play/10084/214943?utm_source=blogtoedu MYSQL日志管理 用于实现MYSQL数据库故障排查2, ...
- mysql 语句_如何记录MySQL执行过的SQL语句
很多时候,我们需要知道 MySQL 执行过哪些 SQL 语句,比如 MySQL 被注入后,需要知道造成什么伤害等等.只要有 SQL 语句的记录,就能知道情况并作出对策.服务器是可以开启 MySQL 的 ...
- mysql删除重复记录语句的方法 作者: 字体:[增加 减小] 类型:转载 时间:2010-06-21 我要评论 查询及删除重复记录的SQL语句,虽然有点乱,但内容还是不错的。 . .
mysql删除重复记录语句的方法 作者: 字体:[增加 减小] 类型:转载 时间:2010-06-21 我要评论 查询及删除重复记录的SQL语句,虽然有点乱,但内容还是不错的. 例如: id name ...
- mysql 怎么查询慢sql语句_Mysql中 查询慢的 Sql语句的记录查找
Mysql中 查询慢的 Sql语句的记录查找 慢查询日志 slow_query_log,是用来记录查询比较慢的sql语句,通过查询日志来查找哪条sql语句比较慢,这样可以对比较慢的sql可以进行优化. ...
- mysql c where_mysql where条件语句优化笔记
where优化主要适用于SELECT查询,当然DELETE和UPDATE语句中也会涉及,这个要大家在平常多积累. 删除不必要的括号: ((a AND b) AND c OR (((a AND b) A ...
- MySQL数据库https接口_第三章 mysql 数据库接口程序以及SQL语句操作
mysql 数据库接口程序以及SQL语句操作 用于管理数据库: 命令接口自带命令 DDL:数据定义语言(create drop ) DCL: 数据控制语言(grant revoke) DML: 数据 ...
- MySQL优化之三:SQL语句优化
一 SQL语句优化的一般步骤: 1 通过show status命令了解各种SQL语句的执行频率 mysql> show status; #show status:显 ...
- mysql 取左_MySQL select语句从字符串左侧获取5个字符
要从字符串的左侧获取字符数,请在MySQL中使用LEFT方法.让我们首先创建一个表-mysql> create table DemoTable ( Name varchar(100) ); 使用 ...
- MySQL日常应用操作记录
1.知道一个字段名,怎样查到它在数据库里的哪张表里? USE Information_schema; SELECT TABLE_NAME FROM COLUMNS WHERE COLUMN_NAME= ...
最新文章
- 2021全国高校计算机能力挑战赛(初赛)Java试题一
- 2029. 石子游戏 IX
- 小甲鱼OD学习第18讲
- JavaScript基础修炼(14)——WebRTC在浏览器中如何获得指定格式的PCM数据【华为云分享】
- Android 系统(42)---Android7.0 PowerManagerService亮灭屏分析(三)
- [导入]C#面向对象设计模式纵横谈(21):(行为型模式) Memento 备忘录模式.zip(9.73 MB)...
- [DSF] Devices Syndication Foundation Architecture V1
- VS配置arduino环境
- 弯曲时空量子场论的历史与现状 (下)
- 【Burp Suite实战指南】【定期更新】
- 外汇交易提醒 ,美元升势停不下来?
- 关于在pyomo框架下无法调用ipopt求解器解决方法
- 机器学习之用Hog+Svm人脸检测、交通标志和字符识别等(初学者)
- 纵向联邦线性模型在线推理过程中成员推断攻击的隐私保护研究
- animate.css插件指南
- python 人民币兑美元汇率代码_人民币对美元汇率的大数据分析与预测【完整代码】...
- RMAN备份恢复性能优化--MAXSETSIZE, MAXPIECESIZE, FILESPERSET, SECTION SIZE等
- 海思HI3559A SDK文档说明
- 《SpringBoot 各种专有名词》
- 公众号榜单 | 2020·5月公众号地区排行榜重磅发布