当前位置:网站首页>MySQL审计插件介绍
MySQL审计插件介绍
2022-07-01 14:56:00 【InfoQ】
1. MySQL 社区版审计日志现状
2. 审计插件使用教程


# 查看 MySQL 插件存放路径
mysql> show variables like 'plugin_dir';
+---------------+------------------------------+
| Variable_name | Value |
+---------------+------------------------------+
| plugin_dir | /usr/local/mysql/lib/plugin/ |
+---------------+------------------------------+
# 将审计插件 server_audit.so 存放到该路径下
[[email protected] plugin]# ls -lh server_audit.so
-rw-r--r--. 1 root root 191K May 4 2021 server_audit.so
# 更改插件属主及权限
[[email protected] plugin]# chown mysql:mysql server_audit.so
[[email protected] plugin]# chmod 755 server_audit.so
[[email protected] plugin]# ls -lh server_audit.so
-rwxr-xr-x. 1 mysql mysql 191K May 4 2021 server_audit.so
# 进入数据库安装审计插件
mysql> INSTALL PLUGIN server_audit SONAME 'server_audit.so';
Query OK, 0 rows affected (0.07 sec)
mysql> show plugins;
+----------------------------+--------+--------------------+-----------------+---------+
| Name | Status | Type | Library | License |
+----------------------------+--------+--------------------+-----------------+---------+
...
| SERVER_AUDIT | ACTIVE | AUDIT | server_audit.so | GPL |
+----------------------------+--------+--------------------+-----------------+---------+
# 查看 audit 初始参数配置
mysql> show variables like '%audit%';
+-------------------------------+-----------------------+
| Variable_name | Value |
+-------------------------------+-----------------------+
| server_audit_events | |
| 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 | OFF |
| 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 |
+-------------------------------+-----------------------+
# 在线开启审计
mysql> set global server_audit_logging=on;
Query OK, 0 rows affected (0.00 sec)
mysql> set global server_audit_events='connect,table,query_ddl,query_dcl,query_dml_no_select';
Query OK, 0 rows affected (0.00 sec)
mysql> set global server_audit_file_path ='/data/mysql/logs/server_audit.log';
Query OK, 0 rows affected (0.00 sec)
mysql> set global server_audit_file_rotate_size=104857600;
Query OK, 0 rows affected (0.01 sec)
# [mysqld]下添加以下配置 使得永久生效
server_audit=FORCE_PLUS_PERMANENT
server_audit_logging=ON
server_audit_file_path=/data/mysql/logs/server_audit.log
server_audit_events=connect,table,query_ddl,query_dcl,query_dml_no_select
server_audit_file_rotate_size=104857600

# 进行操作后 查看审计日志内容
20220512 15:17:17,mysqlhost2,test_user,10.30.21.95,118,0,FAILED_CONNECT,,,1045
20220512 15:17:30,mysqlhost2,test_user,10.30.21.95,119,0,FAILED_CONNECT,,,1045
20220512 15:20:26,mysqlhost2,test_user,10.30.21.95,124,0,CONNECT,,,0
20220512 15:20:49,mysqlhost2,test_user,10.30.21.95,124,395,QUERY,,'create database testdb',0
20220512 15:22:06,mysqlhost2,test_user,10.30.21.95,129,419,QUERY,testdb,'CREATE TABLE if not exists `test_tb0` (\r\n `increment_id` int(11) NOT NULL AUTO_INCREMENT COMMENT \'自增主键\',\r\n `test_id` int(11) NOT
NULL ,\r\n `test_name` varchar(20) DEFAULT NULL,\r\n `create_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT \'创建时间\',\r\n `update_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE C
URRENT_TIMESTAMP COMMENT \'修改时间\',\r\n PRIMARY KEY (`increment_id`)\r\n) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT=\'测试table\'',0
20220512 15:23:09,mysqlhost2,test_user,10.30.21.95,129,426,QUERY,testdb,'insert into test_tb0 (test_id,test_name) values (1001,\'4343df\'),(1002,\'dfd\')',0
20220512 15:23:22,mysqlhost2,test_user,10.30.21.95,129,433,QUERY,testdb,'delete from test_tb0',0
20220512 15:24:14,mysqlhost2,test_user,10.30.21.95,129,448,QUERY,testdb,'create table test_tb0 (id int)',1050
20220512 15:24:25,mysqlhost2,test_user,10.30.21.95,129,452,QUERY,testdb,'drop table test_tb0',0
20220512 15:25:13,mysqlhost2,test_user,10.30.21.95,126,0,DISCONNECT,testdb,,0
# 连接审计主要审计连接数据库、断开连接、连接失败等操作,其日志格式如下:
[timestamp],[serverhost],[username],[host],[connectionid],0,CONNECT,[database],,0
[timestamp],[serverhost],[username],[host],[connectionid],0,DISCONNECT,,,0
[timestamp],[serverhost],[username],[host],[connectionid],0,FAILED_CONNECT,,,[retcode]
# QUERY审计各种数据库变更事件,执行失败也会记录,其日志记录格式如下:
[timestamp],[serverhost],[username],[host],[connectionid],[queryid],QUERY,[database],[object], [retcode]
- 丰富的审计内容:包括用户连接,关闭,DML操作,存储过程,触发器,事件等。
- 灵活的审计策略:可以自定义审计事件,例如过滤掉select查询,或者排除审计某个用户等。
- 灵活方便:免费使用且安装方便,可以在线开启和停用审计功能。
- 开启审计会增加数据库的性能开销,并占用磁盘空间。
- 日志格式不够丰富,不能自定义输出格式。
- https://www.cnblogs.com/lijiaman/p/14257861.html
- https://www.jianshu.com/p/45b37a73e286
- https://mariadb.com/kb/en/mariadb-audit-plugin-options-and-system-variables/
边栏推荐
- 【14. 区间和(离散化)】
- Summary of empty string judgment in the project
- It's settled! 2022 Hainan secondary cost engineer examination time is determined! The registration channel has been opened!
- IDEA全局搜索快捷键(ctrl+shift+F)失效修复
- 【锁】Redis锁 处理并发 原子性
- TypeScript:const
- TypeScript: let
- The data in the database table recursively forms a closed-loop data. How can we get these data
- MIT team used graph neural network to accelerate the screening of amorphous polymer electrolytes and promote the development of next-generation lithium battery technology
- It's suitable for people who don't have eloquence. The benefits of joining the China Video partner program are really delicious. One video gets 3 benefits
猜你喜欢

Problem note - Oracle 11g uninstall

微服务追踪SQL(支持Isto管控下的gorm查询追踪)

Basic operations of SQL database

微服务开发步骤(nacos)

MIT team used graph neural network to accelerate the screening of amorphous polymer electrolytes and promote the development of next-generation lithium battery technology
![[dynamic programming] p1004 grid access (four-dimensional DP template question)](/img/3a/3b82a4d9dcc25a3c9bf26b6089022f.jpg)
[dynamic programming] p1004 grid access (four-dimensional DP template question)

【14. 区间和(离散化)】

The data in the database table recursively forms a closed-loop data. How can we get these data

Opencv learning note 4 -- bank card number recognition

One of the first steps to redis
随机推荐
数字化转型:数据可视化赋能销售管理
[leetcode] 16. The sum of the nearest three numbers
一波三折,终于找到src漏洞挖掘的方法了【建议收藏】
Day-02 database
tensorflow2-savedmodel convert to tflite
These three online PS tools should be tried
[leetcode 324] swing sorting II thinking + sorting
What is the relationship between network speed, broadband, bandwidth and traffic?
IDEA全局搜索快捷键(ctrl+shift+F)失效修复
Salesforce, Johns Hopkins, Columbia | progen2: exploring the boundaries of protein language models
DirectX修复工具V4.1公测![通俗易懂]
Hidden rules of the workplace that must be understood before 30
One of the first steps to redis
What value can NPDP bring to product managers? Do you know everything?
Basic use process of cmake
微信公众号订阅消息 wx-open-subscribe 的实现及闭坑指南
APK签名原理
Yyds dry goods inventory hcie security day13: firewall dual machine hot standby experiment (I) firewall direct deployment, uplink and downlink connection switches
JVM第一话 -- JVM入门详解以及运行时数据区分析
opencv学习笔记五--文件扫描+OCR文字识别