2017年06月02日MySQL社区版本最新版为MySQL_5.7.18,但是该版本不带AUDIT功能(MySQL Enterprise Edition自带AUDIT功能),
因此需要加载plugin(第三方插件),当前插件有以下几种:
1、MySQL Enterprise Audit Plugin – This plugin is not open source and is only available with MySQL Enterprise, which has a significant cost attached to it. It is the most stable and robust.
备注:MySQL企业版本才能使用这个audit插件哦,MySQL社区版慢慢等着吧

2、Percona Audit Log Plugin – Percona provides an open source auditing solution that installs with Percona Server 5.5.37+ and 5.6.17+. This plugin has quite a few output features as it outputs XML, JSON and to syslog. Percona’s implementation is the first to be a drop-in replacement for MySQL Enterprise Audit Plugin. As it has some internal hooks to the server to be feature-compatible with Oracle’s plugin, it is not available as a standalone for other versions of MySQL. This plugin is actively maintained by Percona.
备注:人家说了,我这个插件只能给Percona_sever使用,我Percona来维护

3、McAfee MySQL Audit Plugin – Around the longest and has been used widely. It is open source and robust, while not using the official auditing API. It isn’t updated as often as one may like. There hasn’t been any new features in some time. It was recently updated to support MySQL 5.7
下载地址:http://dl.bintray.com/mcafee/mysql-audit-plugin/
部署可参考:http://blog.csdn.net/bzfys/article/details/53695855
个人发现该插件貌似不支持审计日志自动切割,而且日志格式为JSON格式,个人感觉不易查看,以及时间格式需要转换
eg:"msg-type":"header","date":"1494935783266","audit-version":"1.1.4-707","audit-protocol-version":"1.0","hostname":"salt-master","mysql-version":"5.7.18-log","mysql-program":"/usr/sbin/mysqld","mysql-socket":"/data/mysql/mysql.sock","mysql-port":"3306","server_pid":"43480"}

4、MariaDB Audit Plugin – The only plugin that claims to support MySQL, Percona Server and MariaDB. It is open source and constantly upgraded with new versions of MariaDB. Versions starting at 1.2 are most stable, and it may be risky to use versions below that in your production environment. Versions below 1.2 may be unstable and I have seen it crash production servers. Older versions also log clear text passwords.
下载地址:https://mariadb.com/kb/en/mariadb/about-the-mariadb-audit-plugin/ (可以直接下载MariaDB对应的版本后,解压后在plugin目录下有server_audit.so插件)
MariaDB_5.5.37版本和MariaDB_10.0.10以后版本的audit插件支持MariaDB, MySQL、Percona Server使用
备注:MariaDB_5.x.x和MariaDB_10.x.x区别
MariaDB_5.x.x:兼容MySQL5.x.x的,接口几乎一致,只限于社区版
MariaDB_10.x.x:10.x.x使用新技术,接口会与mysql逐渐区别开来。目标就是以后想MariaDB新接口过渡

因此综合以上,我个人选择了MariaDB Audit Plugin按安装到我的MySQL_5.7.18上,以下为具体部署操作:
1、下载mariadb-5.5.56-linux-x86_64.tar.gz解压获取server_audit.so插件

2、登录MySQL,执行命令获取MySQL的plugin目录
mysql> SHOW GLOBAL VARIABLES LIKE 'plugin_dir';
+---------------+--------------------------+
| Variable_name | Value |
+---------------+--------------------------+
| plugin_dir | /usr/lib64/mysql/plugin/ |
+---------------+--------------------------+
1 row in set (0.02 sec)

3、将server_audit.so上传到 /usr/lib64/mysql/plugin/下

4、在命令下安装server_audit.so
mysql> INSTALL PLUGIN server_audit SONAME 'server_audit.so';

5、查看变量开启设置情况,默认貌似都是关闭的
mysql> show variables like '%audit%';

6、编辑my.cnf,添加配置
server_audit_events='CONNECT,QUERY,TABLE,QUERY_DDL,QUERY_DML,QUERY_DCL'
备注:指定哪些操作被记录到日志文件中
server_audit_logging=on
server_audit_file_path =/data/mysql/auditlogs/
备注:审计日志存放路径,该路径下会生成一个server_audit.log文件,就会记录相关操作记录了
server_audit_file_rotate_size=200000000
server_audit_file_rotations=200
server_audit_file_rotate_now=ON

7、重启服务,service mysqld restart
登录MySQL后发现,在MySQL环境下执行的任何命令都被记录到/data/mysql/auditlogs/server_audit.log,如果日志文件达到指定的大小,会自动切割
mysql> show variables like '%audit%';
+-------------------------------+---------------------------------------------------+
| Variable_name | Value |
+-------------------------------+---------------------------------------------------+
| server_audit_events | CONNECT,QUERY,TABLE,QUERY_DDL,QUERY_DML,QUERY_DCL |
| server_audit_excl_users | |
| server_audit_file_path | /data/mysql/auditlogs/ |
| server_audit_file_rotate_now | ON |
| server_audit_file_rotate_size | 200000000 |
| server_audit_file_rotations | 200 |
| server_audit_incl_users | |
| server_audit_loc_info | |
| server_audit_logging | ON |
| server_audit_mode | 1 |
| server_audit_output_type | file |
| server_audit_query_log_limit | 1024 |
| server_audit_syslog_facility | LOG_USER |
| server_audit_syslog_ident | mysql-server_auditing |
| server_audit_syslog_info | |
| server_audit_syslog_priority | LOG_INFO |
+-------------------------------+---------------------------------------------------+
日志为:
20170516 23:21:23,salt-master,audit_log_user,localhost,4,19,QUERY,,'show variables like \'%audit%\'',0

8、参数说明:
详细请参考:https://mariadb.com/kb/en/mariadb/server_audit-system-variables/
server_audit_output_type:指定日志输出类型,可为SYSLOG或FILE
server_audit_logging:启动或关闭审计
server_audit_events:指定记录事件的类型,可以用逗号分隔的多个值(connect,query,table),如果开启了查询缓存(query cache),查询直接从查询缓存返回数据,将没有table记录
server_audit_file_path:如server_audit_output_type为FILE,使用该变量设置存储日志的文件,可以指定目录,默认存放在数据目录的server_audit.log文件中
server_audit_file_rotate_size:限制日志文件的大小
server_audit_file_rotations:指定日志文件的数量,如果为0日志将从不轮转
server_audit_file_rotate_now:强制日志文件轮转
server_audit_incl_users:指定哪些用户的活动将记录,connect将不受此变量影响,该变量比server_audit_excl_users优先级高
server_audit_syslog_facility:默认为LOG_USER,指定facility
server_audit_syslog_ident:设置ident,作为每个syslog记录的一部分
server_audit_syslog_info:指定的info字符串将添加到syslog记录
server_audit_syslog_priority:定义记录日志的syslogd priority
server_audit_excl_users:该列表的用户行为将不记录,connect将不受该设置影响
server_audit_mode:标识版本,用于开发测试

9、卸载server_audit
mysql> UNINSTALL PLUGIN server_audit;
mysql> show variables like '%audit%';
Empty set (0.00 sec)

防止server_audit 插件被卸载,需要在配置文件中添加:
[mysqld]
server_audit=FORCE_PLUS_PERMANENT
重启MySQL生效

值得注意的是,应该在server_audit插件被安装好,并且已经运行之后添加这些配置,否则过早在配置文件添加这个选项,会导致MySQL发生启动错误!
mysql> UNINSTALL PLUGIN server_audit;
ERROR 1702 (HY000): Plugin 'server_audit' is force_plus_permanent and can not be unloaded

关于MySQL AUDIT(审计)那点事的更多相关文章

  1. Inception服务的安装以及使用Python 3 实现MySQL的审计

    Inception服务的安装以及使用Python实现MySQL的审计 Bison是Inception服务所依赖的包之一,但是某些Linux版本已安装的Bison,或者是通过yum安装的Bison,通常 ...

  2. 利用开源审计插件对mysql进行审计

    转载于互联网 2017年06月02日MySQL社区版本最新版为MySQL_5.7.18,但是该版本不带AUDIT功能(MySQL Enterprise Edition自带AUDIT功能),因此需要加载 ...

  3. mysql 之审计 init-connect+binlog完成审计功能

    mysql基于init-connect+binlog完成审计功能 目前社区版本的mysql的审计功能还是比较弱的,基于插件的审计目前存在于Mysql的企业版.Percona和MariaDB上,但是my ...

  4. MySQL Audit日志审计

    一.简介 数据库审计能够实时记录网络上的数据库活动,对数据库操作进行细粒度审计的合规性管理,对数据库受到的风险行为进行告警,对攻击行为进行阻断,它通过对用户访问数据库行为的记录.分析和汇报,用来帮助用 ...

  5. MySQL 添加审计功能

    MySQL社区版没有自带的设计功能或插件.调研发现MariaDB的audit plugin 同样适用于MySQL,支持更细粒度的审计,比如只审计DDL操作,满足我们的需求.因为最近测试环境的某表结构经 ...

  6. Mysql开启审计功能

    第一种经验证,有效. 第一种用macfee的mysql审计插件. 下载地址:https://bintray.com/mcafee/mysql-audit-plugin/release/1.1.4-72 ...

  7. linux中的audit审计日志

    这里首先介绍auditctl的应用,具体使用指南查看man auditctl.auditctl的man 描述说明这个工具主要是用来控制audit系统行为,获取audit系统状态,添加或者删除audit ...

  8. oracle开启audit(审计)

    1.查看审计功能是否开启(本机已经开启,如果audit_sys_operations值为FALSE就是没开审计) [sql] view plaincopyprint? SQL> CONN /AS ...

  9. linux audit审计(8)--开启audit对系统性能的影响

    我们使用测试性能的工具,unixbench,它有一下几项测试项目: Execl Throughput 每秒钟执行 execl 系统调用的次数 Pipe Throughput 一秒钟内一个进程向一个管道 ...

随机推荐

  1. 分享几个高效编写JS 的心得

    原则 不要做任何优化除非的确需要优化   任何的性能优化都必须以测量数据为基础,如果你怀疑代码存在性能问题,首先通过测试来验证你的想法.性能优化三问 我还能做哪些工作从而让代码变得更有效率? 流行的J ...

  2. CodeForces - 1017F. The Neutral Zone (数学+Bitset存素数+素数筛优化)

    Notice: unusual memory limit! After the war, destroyed cities in the neutral zone were restored. And ...

  3. 洛谷 P4547 & bzoj 5006 随机二分图 —— 状压DP+期望

    题目:https://www.luogu.org/problemnew/show/P4547 https://www.lydsy.com/JudgeOnline/problem.php?id=5006 ...

  4. VijosP1274:神秘的咒语

    描述 身为拜月教的高级间谍,你的任务总是逼迫你出生入死.比如这一次,拜月教主就派你跟踪赵灵儿一行,潜入试炼窟底. 据说试炼窟底藏着五行法术的最高法术:风神,雷神,雪妖,火神,山神的咒语.为了习得这些法 ...

  5. Velocity常用标签的讲解

    Velocity是一个基于java的模板引擎(template engine).它允许任何人仅仅简单的使用模板语言(template language)来引用由java代码定义的对象. 当Veloci ...

  6. ES6学习之Symbol

    定义:一种新的原始数据类型,表示独一无二的值 const a = Symbol(); const b = Symbol("foo") //接收参数的Symbol,参数表示对Symb ...

  7. SpringMvc之参数绑定注解详解之二

    2 consumes.produces 示例 cousumes的样例: 1 @Controller   2 @RequestMapping(value = "/pets", met ...

  8. VC 绘图,使用双缓冲技术实现

    VC 绘图,使用双缓冲技术实现 - Cloud-Datacenter-Renewable Energy-Big Data-Model - 博客频道 - CSDN.NET VC 绘图,使用双缓冲技术实现 ...

  9. eclipse个人觉得有用的快捷键

    CTRL+SHIFT+F 自动整理代码格式 CTRL+M 最大/还原当前编辑窗口 CTRL+/ 注释当前行 CTRL+1 快速修复 CTRL+D 删除当前行 SHIFT+ENTER 在当前行前面插入空 ...

  10. Java基础——java中String、StringBuffer、StringBuilder的区别

    (转自:http://www.cnblogs.com/xudong-bupt/p/3961159.html) java中String.StringBuffer.StringBuilder是编程中经常使 ...