当前位置:网站首页>Introduction to MySQL audit plug-in
Introduction to MySQL audit plug-in
2022-07-01 15:00:00 【InfoQ】
1. MySQL Status of community audit log
2. Audit plug-in tutorial


# see MySQL Plug in storage path
mysql> show variables like 'plugin_dir';
+---------------+------------------------------+
| Variable_name | Value |
+---------------+------------------------------+
| plugin_dir | /usr/local/mysql/lib/plugin/ |
+---------------+------------------------------+
# Add the audit plug-in server_audit.so Store in this path
[[email protected] plugin]# ls -lh server_audit.so
-rw-r--r--. 1 root root 191K May 4 2021 server_audit.so
# Change the owner and permission of the plug-in
[[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
# Enter the database and install the audit plug-in
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 |
+----------------------------+--------+--------------------+-----------------+---------+
# see audit Initial parameter configuration
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 |
+-------------------------------+-----------------------+
# Open audit online
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] Add the following configuration Make it permanent
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

# After the operation Check the contents of the audit log
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 \' Since the primary key \',\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 \' Creation time \',\r\n `update_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE C
URRENT_TIMESTAMP COMMENT \' Modification time \',\r\n PRIMARY KEY (`increment_id`)\r\n) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT=\' test 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
# Connection audit mainly audits the connection database 、 disconnect 、 Connection failure and other operations , The log format is as follows :
[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 Audit various database change events , Execution failure will also be recorded , The log record format is as follows :
[timestamp],[serverhost],[username],[host],[connectionid],[queryid],QUERY,[database],[object], [retcode]
- Rich audit content : Including user connections , close ,DML operation , stored procedure , trigger , Events, etc. .
- Flexible audit strategy : You can customize audit events , For example, filter out select Inquire about , Or exclude auditing a user, etc .
- Flexible and convenient : It is free to use and easy to install , The audit function can be enabled and disabled online .
- Opening the audit will increase the performance cost of the database , And take up disk space .
- The log format is not rich enough , You cannot customize the output format .
- 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/
边栏推荐
- 三十之前一定要明白的职场潜规则
- IDEA全局搜索快捷键(ctrl+shift+F)失效修复
- solidty-基础篇-基础语法和定义函数
- opencv学习笔记六--图像特征[harris+SIFT]+特征匹配
- [Verilog quick start of Niuke series] ~ multi function data processor, calculate the difference between two numbers, use generate... For statement to simplify the code, and use sub modules to realize
- Pat 1065 a+b and C (64bit) (20 points) (16 points)
- 竣达技术丨多台精密空调微信云监控方案
- C#学习笔记(5)类和继承
- JVM second conversation -- JVM memory model and garbage collection
- Hidden rules of the workplace that must be understood before 30
猜你喜欢

241. Design priorities for operational expressions
![Opencv Learning Notes 6 -- image feature [harris+sift]+ feature matching](/img/50/5c8adacea78e470c255070c8621ddd.png)
Opencv Learning Notes 6 -- image feature [harris+sift]+ feature matching

The markdown editor uses basic syntax
![[14. Interval sum (discretization)]](/img/e5/8b29aca7068a6385e8ce90c2742c37.png)
[14. Interval sum (discretization)]
![[zero basic IOT pwn] reproduce Netgear wnap320 rce](/img/f7/d683df1d4b1b032164a529d3d94615.png)
[zero basic IOT pwn] reproduce Netgear wnap320 rce

Opencv Learning Notes 6 -- image mosaic

JVM第一话 -- JVM入门详解以及运行时数据区分析

Semiconductor foundation of binary realization principle

Take you to API development by hand

OpenSSL client programming: SSL session failure caused by an insignificant function
随机推荐
Flink 系例 之 TableAPI & SQL 与 MYSQL 分组统计
竣达技术丨室内空气环境监测终端 pm2.5、温湿度TVOC等多参数监测
微信公众号订阅消息 wx-open-subscribe 的实现及闭坑指南
241. Design priorities for operational expressions
What value can NPDP bring to product managers? Do you know everything?
[getting started with Django] 13 page Association MySQL "multi" field table (check)
Microservice development steps (Nacos)
tensorflow2-savedmodel convert to tflite
opencv学习笔记四--银行卡号识别
数字化转型:数据可视化赋能销售管理
Flink 系例 之 TableAPI & SQL 与 Kafka 消息插入
APK签名原理
Hidden rules of the workplace that must be understood before 30
基于价值量化的需求优先级排序方法
Cannot link redis when redis is enabled
微信网页订阅消息实现
Markdown编辑器使用基本语法
Opencv Learning Notes 6 -- image feature [harris+sift]+ feature matching
What data capabilities do data product managers need to master?
NPDP产品经理国际认证报名有什么要求?