Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

MySQL uses tee to record statements and output logs

2025-02-27 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)06/01 Report--

From the mysql command line, you can record statements and output to a specified file using the tee command. It can be very useful in debugging.

Each time a statement is executed, mysql refreshes the execution result to the specified file. The Tee feature takes effect only in interactive mode.

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.01sec)

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 | 1600 | 30 |

| | 7521 | WARD | SALESMAN | 7698 | 1981-02-22 00:00:00 | 1250 | 1250 | 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)

Use the notee command to turn off logging

Mysql > notee

Outfile disabled.

View the generated log

[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.01sec)

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 | 1600 | 30 |

| | 7521 | WARD | SALESMAN | 7698 | 1981-02-22 00:00:00 | 1250 | 1250 | 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

When mysql is called, you can log all logs for this login session using the-- tee parameter.

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

View the generated log

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

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report