一、插件地址
https://github.com/mcafee/mysql-audit
解压
# unzip audit-plugin-mysql-5.7-1.1.4-725-linux-x86_64.zip
将下载到的插件安装包中lib/libaudit_plugin.so复制到mysql插件目录中,并加上执行权限
查看当前mysql插件目录
show global variables like 'plugin_dir';
拷贝插件到目录,并赋权
chown -R mysql:mysql
chown -R 775 插件
执行插件安装包中的offset-extract.sh,获取offsets值对插件安装包中的offset-extract.sh赋执行权限并运行,获取offsets值
chmod +x utils/offset-extract.sh
./utils/offset-extract.sh /usr/sbin/mysqld

从第3列7832开始到0为offsets值。
添加配置my.cnf
[mysqld]
audit_json_file = on
plugin-load=AUDIT=libaudit_plugin.so
audit_record_cmds='insert,delete,update,create,drop,alter,grant,truncate'
audit_json_log_file=/home/mysql/mysql-audit.json
audit_offsets =7832, 7880, 3640, 4800, 456, 360, 0, 32, 64, 160, 544, 7996, 4368, 3656, 3664, 3668, 6080, 2072, 8, 7064, 7104, 7088, 13480, 148, 672, 0
进入mysql命令窗口,安装插件
INSTALL PLUGIN AUDIT SONAME 'libaudit_plugin.so';
查看版本:
show global status like '%audit%';
查看插件有哪些可配置的参数:
SHOW GLOBAL VARIABLES LIKE '%audi%';
插件卸载
需要在 my.cnf 中 [mysqld] 下添加 audit_uninstall_plugin=1,重启mysql。重启完毕后执行两次 UNINSTALL PLUGIN AUDIT; 即可卸载。
卸载完成后需要从 my.cnf 中删除 audit_uninstall_plugin=1 ,否则下次mysql启动会报错:[ERROR] /data/mysql/bin/mysqld: unknown variable 'audit_uninstall_plugin=1'