当前位置:网站首页>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/
边栏推荐
- Generate random numbers (4-bit, 6-bit)
- What are the requirements for NPDP product manager international certification registration?
- Chapter 4 of getting started with MySQL: creation, modification and deletion of data tables
- 【LeetCode】16、最接近的三数之和
- Use the npoi package of net core 6 C to read excel Pictures in xlsx cells and stored to the specified server
- TypeScript: let
- DirectX修复工具V4.1公测![通俗易懂]
- JVM second conversation -- JVM memory model and garbage collection
- Solid basic basic grammar and definition function
- Vnctf2022 open web gocalc0
猜你喜欢

官宣:Apache Doris 顺利毕业,成为 ASF 顶级项目!

JVM performance tuning and practical basic theory part II
![[leetcode 324] swing sorting II thinking + sorting](/img/cb/26d89e1a1f548b75a5ef9f29eebeee.png)
[leetcode 324] swing sorting II thinking + sorting

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

cmake 基本使用过程

Blog recommendation | in depth study of message segmentation in pulsar

The first technology podcast month will be broadcast soon

Word2vec yyds dry goods inventory

Minimum spanning tree and bipartite graph in graph theory (acwing template)

炎炎夏日,这份安全用气指南请街坊们收好!
随机推荐
三十之前一定要明白的职场潜规则
tensorflow2-savedmodel convert to tflite
写在Doris毕业后的第一天
Internet hospital system source code hospital applet source code smart hospital source code online consultation system source code
[零基础学IoT Pwn] 复现Netgear WNAP320 RCE
Tensorflow 2. X realizes iris classification
职场太老实,总被欺负怎么办?
MIT team used graph neural network to accelerate the screening of amorphous polymer electrolytes and promote the development of next-generation lithium battery technology
[零基础学IoT Pwn] 复现Netgear WNAP320 RCE
These three online PS tools should be tried
Music player development example (can be set up)
TypeScript:const
TypeScript: let
数字化转型:数据可视化赋能销售管理
The data in the database table recursively forms a closed-loop data. How can we get these data
Use the npoi package of net core 6 C to read excel Pictures in xlsx cells and stored to the specified server
OpenSSL client programming: SSL session failure caused by an insignificant function
问题随记 —— Oracle 11g 卸载
Demand prioritization method based on value quantification
What is the relationship between network speed, broadband, bandwidth and traffic?