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)
查看生成的日志 [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时,使用--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)