sql_log_off参数,是会话级别的参数。使用前提是general_log是开启状态。

    这个变量控制是否记录到通用查询日志,默认值是0(做记录)。更改当前会话记录,改变这一变量的会话值。会话的用户必须拥有超级特权。

    该参数对于数据的审计有一定的控制作用。

    在general_log=1启用状态,设置sql_log_off的值,体验该参数对审计的作用。

    (1)设置sql_log_off=0或者OFF状态

mysql> set sql_log_off=OFF;

Query OK, 0 rows affected (0.00 sec)


mysql> show variables like 'sql_log_off';

+---------------+-------+

| Variable_name | Value |

+---------------+-------+

| sql_log_off   | OFF   |

+---------------+-------+

1 row in set (0.00 sec)

    创建一张测试表:

mysql> create table t(id int);

Query OK, 0 rows affected (0.01 sec)

    查看general_log:

[root@gflinux4 data]# more gflinux4.log 

/usr/local/mysql/bin/mysqld, Version: 5.6.20-log (Source distribution). started with:

Tcp port: 3306  Unix socket: /tmp/mysql.sock

Time                 Id Command    Argument

......

141211  3:47:41    4 Query create table t(id int)

     (2)设置sql_log_off=1或者ON状态

mysql> set sql_log_off=1;

Query OK, 0 rows affected (0.00 sec)


mysql> show variables like 'sql_log_off';

+---------------+-------+

| Variable_name | Value |

+---------------+-------+

| sql_log_off   | ON    |

+---------------+-------+

1 row in set (0.00 sec)

    删除表t:

mysql> DROP TABLE t;

Query OK, 0 rows affected (0.01 sec)

    再次查看general_log:

[root@gflinux4 data]# more gflinux4.log 

/usr/local/mysql/bin/mysqld, Version: 5.6.20-log (Source distribution). started with:

Tcp port: 3306  Unix socket: /tmp/mysql.sock

Time                 Id Command    Argument

......

141211  4:02:48    4 Query set sql_log_off=1

    并没有记录删除的内容。

     (3)再次设置sql_log_off=0或者OFF状态

    在没有开启审计之前,先创建t表。

mysql> create table t(id int);

Query OK, 0 rows affected (0.00 sec)


mysql> set sql_log_off=0;

Query OK, 0 rows affected (0.00 sec)

    插入数据:

mysql> insert into t select 1;

Query OK, 1 row affected (0.00 sec)

Records: 1  Duplicates: 0  Warnings: 0

    再次查看general_log:

[root@gflinux4 data]# more gflinux4.log 

/usr/local/mysql/bin/mysqld, Version: 5.6.20-log (Source distribution). started with:

Tcp port: 3306  Unix socket: /tmp/mysql.sock

Time                 Id Command    Argument

......

141211  4:07:12    4 Query insert into t select 1

    因此该参数对于开启查询日志来说,对于会话级别的审计尤为重要,值得关注。