Home > Database > Mysql Tutorial > body text

MySQL5.5.28介绍的Audit功能_MySQL

WBOY
Release: 2016-06-01 13:48:13
Original
1388 people have browsed it

bitsCN.com

 

该功能是一个commercial extension.它是被包含在MySQL Enterprise Edition的。所以社区版本可能就无法使用了。

虽然文档上是说它在5.5.28被包含在plugin目录下,不过在前几个版本(比如5.5.25a、5.5.24等)也是存在的。只不过可能开发并未完善(早期的版本中包含的audit plugin加载后,可控参数较少)。

如果想尝试它,可以去下载5.5.28的商业版本(5.5.25a也可以),安装5.5.28的过程不表,安装audit功能有两种方法,一是编辑my.cnf的配置文件(举例的环境皆是linux_64),添加如下语句:

[mysqld]plugin-load=audit_log.so
Copy after login

然后在启动MySQL时,在启动命令中加入选项'--plugin-load',这种方法的缺点是每次DB启动时都要加上该选项。牵扯到DB start/stop/restart的安装方法都是浮云,所以这种方法不推荐。

二(好吧,装傻只是瞬间,真二才是永恒)是直接使用install plugin语句register该插件:

mysql> INSTALL PLUGIN audit_log SONAME 'audit_log.so';
Copy after login

该语句成功运行后,会在mysql.plugins表中看到该插件的记录:

mysql> select * from mysql.plugin;+-----------+--------------+| name      | dl           |+-----------+--------------+| audit_log | audit_log.so |+-----------+--------------+
Copy after login

此时,audit就已经开始工作了。它会在数据目录(默认)下产生一个名为'audit.log'(默认)的未加密XML文档。

目前MySQL Enterprise Audit 可记录login 或 query events.并且有多个限制,其中比较大的限制是只能记录top-level的语句,包含在triggers、procedures的语句暂时不能记录。其文件记录片段如下:

<?xml version="1.0" encoding="UTF-8"?><audit>  <audit_record timestamp="2012-08-02T14:52:12" name="Audit" server_id="150514" version="1" startup_options="--port=3306" os_version="i686-Linux" mysql_version="5.5.28-debug-log"></audit_record>  <audit_record timestamp="2012-08-02T14:52:41" name="Connect" connection_id="1" status="0" user="root" priv_user="root" os_login="" proxy_user="" host="localhost" ip="127.0.0.1" db=""></audit_record>  <audit_record timestamp="2012-08-02T14:53:45" name="Query" connection_id="1" status="0" sqltext="INSERT INTO t1 () VALUES()"></audit_record>  <audit_record timestamp="2012-08-02T14:53:51" name="Quit" connection_id="1" status="0"></audit_record>  <audit_record timestamp="2012-08-06T14:21:03" name="NoAudit" server_id="150514"></audit_record></audit>
Copy after login

5.5.28中的audit有如下可控参数:

mysql> SHOW VARIABLES LIKE 'audit_log%'; +--------------------------+--------------+| Variable_name            | Value        |+--------------------------+--------------+| audit_log_buffer_size    | 1048576      || audit_log_file           | audit.log    || audit_log_flush          | OFF          || audit_log_policy         | ALL          || audit_log_rotate_on_size | 0            || audit_log_strategy       | ASYNCHRONOUS |+--------------------------+--------------+
Copy after login

这几个参数大多可从字面上理解其意义,比较关键的参数是:

 audit_log_policy : 控制记录哪些类型的审计记录,有效值为:ALL(log all events)、NONE(login nothing(disable the audit stream))、LOGINS(log only login events)、QUERIES(log only query events)

详情可参阅:

http://dev.mysql.com/doc/refman/5.5/en/mysql-enterprise-audit.html

bitsCN.com
Related labels:
yes
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template