mysql查询日志

1.查看查询日志配置

mysql> show variables like 'general_log%';
+------------------+------------------+
| Variable_name    | Value            |
+------------------+------------------+
| general_log      | ON               |
| general_log_file | /tmp/general.log |
+------------------+------------------+
2 rows in set (0.00 sec)

mysql> show variables like 'log_output%';
+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| log_output    | FILE  |
+---------------+-------+
1 row in set (0.00 sec)


2.修改
mysql> set global general_log=0;
Query OK, 0 rows affected (0.01 sec)


mysql> show variables like 'general_log%';
+------------------+------------------+
| Variable_name    | Value            |
+------------------+------------------+
| general_log      | OFF              |
| general_log_file | /tmp/general.log |
+------------------+------------------+
2 rows in set (0.00 sec)

或者编辑/etc/my.cnf
general_log=on
log_output=file
general_log_file='/tmp/general.log'

3.查看查询日志内容

150817  1:55:05     1 Query     desc user
150817  1:55:21     1 Query     select user,machine,password from user where user='root'
150817  1:55:39     1 Query     select user,host,password from user where user='root'
150817  1:56:00     1 Quit
150817  1:56:06     2 Connect   root@localhost on
                    2 Query     select @@version_comment limit 1
150817  1:56:10     2 Quit
150817  1:56:15     3 Connect   a@localhost as  on
                    3 Query     select @@version_comment limit 1
150817  1:56:16     3 Quit
150817  1:56:20     4 Connect   root@localhost on
                    4 Query     select @@version_comment limit 1
150817  1:56:30     4 Query     SELECT DATABASE()
                    4 Init DB   mysql
                    4 Query     show databases
                    4 Query     show tables
                    4 Field List        columns_priv
                    4 Field List        db
                    4 Field List        event
                    4 Field List        func
                    4 Field List        general_log
                    4 Field List        help_category
                    4 Field List        help_keyword

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/10972173/viewspace-1775189/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/10972173/viewspace-1775189/