MySQL Audit Plugin

MySQL Audit Plugin

The purpose of the MariaDB Audit Plugin is to log the server's activity. Records about who connected to the server, what queries ran and what tables were touched can be stored to the rotating log file or sent to the local syslogd.

MySQL5.5 之后添加了审计插件(Audit Plugin),该插件是MariaDB中默认自带的插件,MySQL中可以添加该插件后进行使用。

1.上传插件

--将对应版本插件上传至mysql插件目录下
shell> mv /opt/server_audit7.so /opt/mysql-5.7.18-linux-glibc2.5-x86_64/lib/plugin/

2.安装插件

--进入mysql
shell> mysql -uroot -p
Enter password: 
    
--安装审计插件
mysql> INSTALL PLUGIN server_audit SONAME 'server_audit7.so';

--查看相应参数
mysql> show variables like ''%server_audit%'';

--开启审计
mysql> set global server_audit_logging = 1;
    
--设置审计事件,永久生效至my.cnf中修改
mysql> set global server_audit_events='connect,query,table';
    
--重新进入mysql查看对应参数
mysql> show variables like ''%server_audit%'';

+-------------------------------+-----------------------+
| Variable_name                 | Value                 |
+-------------------------------+-----------------------+
| server_audit_events           | CONNECT,QUERY,TABLE   |
| server_audit_excl_users       |                       |
| server_audit_file_path        | server_audit.log      |
| server_audit_file_rotate_now  | OFF                   |
| server_audit_file_rotate_size | 1000000               |
| server_audit_file_rotations   | 9                     |
| 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              |
+-------------------------------+-----------------------+

3.审计日志

shell> cat /data/mysql_data/server_audit.log
20170713 01:53:12,localhost.localdomain,root,localhost,8,0,DISCONNECT,,,0
j20170713 01:53:44,localhost.localdomain,root,localhost,9,0,CONNECT,,,0
20170713 01:53:44,localhost.localdomain,root,localhost,9,24,QUERY,,'select @@version_comment limit 1',0
20170713 01:53:56,localhost.localdomain,root,localhost,9,25,QUERY,,'select * from mysql.user',0

4.审计参数

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:标识版本,用于开发测试

5.相关链接

附件下载
About the MariaDB Audit Plugin

posted @ 2017-07-12 18:49  Xuty  阅读(504)  评论(0编辑  收藏  举报