本文共 1413 字,大约阅读时间需要 4 分钟。
如果有一天数据库里丢失了一条记录,开发让你查什么时候被谁从哪个IP,执行了delete操作,那么在之前的版本是无法查到的,而Percona最新版本5.6.17首次提供了审计日志功能。
(注:截止2014年5月19日,官方MySQL5.6.17社区版和MariaDB10.0.11均没有提供该功能)
版本:
1 | 5.6 . 17 - 65.0 -rel65. 0 -log Percona Server with XtraDB (GPL), Release rel65. 0 , Revision 587 |
安装插件:
1 | INSTALL PLUGIN audit_log SONAME 'audit_log.so' ; |
show plugins;你会发现
1 | | audit_log | ACTIVE | AUDIT | audit_log.so | GPL | |
变量参数:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | mysql> show global var iables like 'audit%' ; +--------------------------+--------------+ | Variable_name | Value | +--------------------------+--------------+ | audit_log_buffer_size | 1048576 | | audit_log_file | audit.log | | audit_log_flush | OFF | | audit_log_format | NEW | | audit_log_policy | ALL | | audit_log_rotate_on_size | 0 | | audit_log_rotations | 0 | | audit_log_strategy | ASYNCHRONOUS | +--------------------------+--------------+ 8 rows in set ( 0.00 sec) |
它先会把日志写入内存,然后再刷入磁盘里。
audit_log_strategy参数可以调整下面4个策略
1 2 3 4 | 1 、ASYNCHRONOUS log using memory buffer, do not drop events if buffer is full 2 、PERFORMANCE log using memory buffer, drop events if buffer is full 3 、SEMISYNCHRONOUS log directly to file, do not fsync every event 4 、SYNCHRONOUS log directly to file, fsync every event |
4种策略性能压力测试:
这里用默认就可以。
audit_log_rotate_on_size参数表示超过定义的值,会自动轮训,切分日志。
audit_log_rotations参数限制表示文件的数量。
效果:
参考文献:
本文转自hcymysql51CTO博客,原文链接: http://blog.51cto.com/hcymysql/1413670,如需转载请自行联系原作者