一:直接从mariadb的GA版本中提取server_audit{.so|.dll},根据测试,不支持 Mysql 8+
主要的、最近的版本 都已经是 1.4.4+: 完整的功能了。
CONNECT, QUERY, TABLE, QUERY_DDL, QUERY_DML, QUERY_DCL, QUERY_DML_NO_SELECT (MariaDB Audit Plugin >= 1.4.4)
二:根据测试,Mysql可以通过--plugin-load选项加载; 通过install plugin方式加载在重启mysqld服务器后会出现问题!
三:基本配置
plugin-load=server_audit=server_audit.dll server_audit=force_plus_permanent server_audit_logging=on server_audit_output_type=file server_audit_file_path=d:/server_audit.log server_audit_file_rotate_size=1024024024 server_audit_query_log_limit=2048
四:参考资料
A full list of related system variables is detailed on the Server_Audit System Variables page, and status variables on the Server_Audit Status Variables page of this documentation. Some of the major ones are highlighted below:
| Type | Description | Introduced |
|---|---|---|
| CONNECT | Connects, disconnects and failed connects—including the error code | |
| QUERY | Queries executed and their results in plain text, including failed queries due to syntax or permission errors | |
| TABLE | Tables affected by query execution | |
| QUERY_DDL | Same as QUERY, but filters only DDL-type queries (CREATE, ALTER, DROP, RENAME and TRUNCATE statements—except CREATE/DROP [PROCEDURE / FUNCTION / USER] and RENAME USER (they‘re not DDL) |
MariaDB 5.5.42. MariaDB 10.0.17, MariaDB 10.1.4 |
| QUERY_DML | Same as QUERY, but filters only DML-type queries (DO, CALL, LOAD DATA/XML, DELETE, INSERT, SELECT, UPDATE, HANDLER and REPLACE statements) |
MariaDB 5.5.42, MariaDB 10.0.17, MariaDB 10.1.4 |
| QUERY_DML_NO_SELECT | Same as QUERY_DML, but doesn‘t log SELECT queries. (since version 1.4.4) (DO, CALL, LOAD DATA/XML, DELETE, INSERT, UPDATE, HANDLER and REPLACE statements) |
MariaDB 5.5.42, MariaDB 10.0.17, MariaDB 10.1.4 |
| QUERY_DCL | Same as QUERY, but filters only DCL-type queries (CREATE USER, DROP USER, RENAME USER, GRANT, REVOKE and SET PASSWORD statements) |
MariaDB 5.5.43, MariaDB 10.0.18, MariaDB 10.1.5 |
Since there are other types of queries besides DDL and DML, using the QUERY_DDL and QUERY_DML options together is not equivalent to using QUERY. Starting in version 1.3.0 of the Audit Plugin, there is the QUERY_DCL option for logging DCL types of queries (e.g., GRANT and REVOKE statements). In the same version, the server_audit_query_log_limit variable was added to be able to set the length of a log record. Previously, a log entry would be truncated due to long query strings.
CONNECT, QUERY, TABLE (MariaDB Audit Plugin < 1.2.0)CONNECT, QUERY, TABLE, QUERY_DDL, QUERY_DML (MariaDB Audit Plugin >= 1.2.0)CONNECT, QUERY, TABLE, QUERY_DDL, QUERY_DML, QUERY_DCL (MariaDB Audit Plugin >=1.3.0)CONNECT, QUERY, TABLE, QUERY_DDL, QUERY_DML, QUERY_DCL, QUERY_DML_NO_SELECT (MariaDB Audit Plugin >= 1.4.4)Below is a list of the releases of the MariaDB Audit Plugin, the most recent version first, and in which versions of MariaDB each plugin version was included.
There are a several options and system variables related to the MariaDB Audit Plugin, once it has been installed. System variables can be displayed using the SHOW VARIABLES statement like so:
SHOW GLOBAL 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_logging | ON |
| server_audit_mode | 0 |
| 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 |
+-------------------------------+-----------------------+
To change the value of one of these variables, you can use the SET statement, or set them at the command-line when starting MariaDB. It‘s recommended that you set them in the MariaDB configuration for the server like so:
[mariadb] ... server_audit_excl_users=‘bob,ted‘ ...
Below is a list of all system variables related to the Audit Plugin. See Server System Variables for a complete list of system variables and instructions on setting them. See also the full list of MariaDB options, system and status variables.
server_audit_events--server-audit-events=valuestringCONNECT, QUERY, TABLE (MariaDB Audit Plugin < 1.2.0)CONNECT, QUERY, TABLE, QUERY_DDL, QUERY_DML (MariaDB Audit Plugin >= 1.2.0)CONNECT, QUERY, TABLE, QUERY_DDL, QUERY_DML, QUERY_DCL (MariaDB Audit Plugin >=1.3.0)CONNECT, QUERY, TABLE, QUERY_DDL, QUERY_DML, QUERY_DCL, QUERY_DML_NO_SELECT (MariaDB Audit Plugin >= 1.4.4)server_audit_excl_usersSET GLOBAL server_audit_excl_users=‘user_foo, user_bar‘. CONNECT records aren‘t affected by this variable - they are always logged. The user is still logged if it‘s specified in server_audit_incl_users.--server-audit-excl-users=valuestringserver_audit_file_path--server-audit-file-path=valuestringserver_audit.logserver_audit_file_rotate_now--server-audit-rotate-now[={0|1}]booleanOFFserver_audit_file_rotate_size--server-audit-rotate-size=#numeric1000000server_audit_file_rotations--server-audit-rotations=#numeric90 to 999server_audit_incl_usersSET GLOBAL server_audit_incl_users=‘user_foo, user_bar‘. CONNECT records aren‘t affected by this variable - they are always logged. This setting has higher priority than server_audit_excl_users. So if the same user is specified both in incl_ and excl_ lists, they will still be logged.--server-audit-incl-users=valuestringserver_audit_loc_infostringserver_audit_loggingSET GLOBAL server_audit_logging=on If the server_audit_output_type is FILE, this will actually create/open the logfile so the server_audit_file_path should be properly specified beforehand. Same about the SYSLOG-related parameters. The logging is turned off by default.--server-audit-logging[={0|1}]booleanOFFserver_audit_mode--server-audit-mode[=#]server_audit_output_typeSET GLOBAL server_audit_output_type=file file: log records will be saved into the rotating log file. The name of the file set by server_audit_file_path variable. syslog: log records will be sent to the local syslogd daemon with the standard <syslog.h> API. The default value is ‘file‘.--server-audit-output-type=valueenumfileSYSLOG or FILEserver_audit_query_log_limit--server-audit-query-log-limit=#numeric10240 to 2147483647server_audit_syslog_facility--server-audit-syslog-facility=valueenumLOG_USERLOG_USER, LOG_MAIL, LOG_DAEMON, LOG_AUTH, LOG_SYSLOG, LOG_LPR, LOG_NEWS, LOG_UUCP, LOG_CRON, LOG_AUTHPRIV, LOG_FTP, and LOG_LOCAL0–LOG_LOCAL7.server_audit_syslog_ident--server-audit-syslog-ident=valuestringmysql-server_auditingserver_audit_syslog_info--server-audit-syslog-info=valuestringserver_audit_syslog_priority--server-audit-syslog-priority=valueenumLOG_INFOLOG_EMERG, LOG_ALERT, LOG_CRIT, LOG_ERR, LOG_WARNING, LOG_NOTICE, LOG_INFO, LOG_DEBUGserver_auditOFF - Disables the plugin without removing it from the mysql.plugins table.ON - Enables the plugin. If the plugin cannot be initialized, then the server will still continue starting up, but the plugin will be disabled.FORCE - Enables the plugin. If the plugin cannot be initialized, then the server will fail to start with an error.FORCE_PLUS_PERMANENT - Enables the plugin. If the plugin cannot be initialized, then the server will fail to start with an error. In addition, the plugin cannot be uninstalled with UNINSTALL SONAME or UNINSTALL PLUGIN while the server is running.--server-audit=valenumeratedONOFF, ON, FORCE, FORCE_PLUS_PERMANENT
Mysql:来源于Mariadb的【审计】插件:server_audit
原文:https://www.cnblogs.com/jinzhenshui/p/12493569.html