MySQL :: MySQL 5.7 Reference Manual :: 6.4.5.11 Audit Log Reference (original) (raw)

6.4.5.11 Audit Log Reference

Audit Log Tables

MySQL Enterprise Audit uses tables in the mysql system database for persistent storage of filter and user account data. The tables can be accessed only by users who have privileges for that database. The tables use theInnoDB storage engine (MyISAM prior to MySQL 5.7.21).

If these tables are missing, the audit_log plugin operates in legacy mode. SeeSection 6.4.5.10, “Legacy Mode Audit Log Filtering”.

The audit_log_filter table stores filter definitions. The table has these columns:

The audit_log_user table stores user account information. The table has these columns:

Audit Log Functions

This section describes, for each audit log function, its purpose, calling sequence, and return value. For information about the conditions under which these functions can be invoked, see Section 6.4.5.7, “Audit Log Filtering”.

Each audit log function returns a string that indicates whether the operation succeeded. OK indicates success. ERROR:_`message`_ indicates failure.

Audit log functions treat string arguments as binary strings (which means they do not distinguish lettercase), and string return values are binary strings.

If an audit log function is invoked from within themysql client, binary string results display using hexadecimal notation, depending on the value of the--binary-as-hex. For more information about that option, see Section 4.5.1, “mysql — The MySQL Command-Line Client”.

These audit log functions are available:

mysql> SELECT audit_log_encryption_password_get();  
+-------------------------------------+  
| audit_log_encryption_password_get() |  
+-------------------------------------+  
| secret                              |  
+-------------------------------------+  
mysql> SELECT audit_log_encryption_password_set(password);  
+---------------------------------------------+  
| audit_log_encryption_password_set(password) |  
+---------------------------------------------+  
| 1                                           |  
+---------------------------------------------+  
mysql> SELECT audit_log_filter_flush();  
+--------------------------+  
| audit_log_filter_flush() |  
+--------------------------+  
| OK                       |  
+--------------------------+  
mysql> SELECT audit_log_filter_remove_filter('SomeFilter');  
+----------------------------------------------+  
| audit_log_filter_remove_filter('SomeFilter') |  
+----------------------------------------------+  
| OK                                           |  
+----------------------------------------------+  
mysql> SELECT audit_log_filter_remove_user('user1@localhost');  
+-------------------------------------------------+  
| audit_log_filter_remove_user('user1@localhost') |  
+-------------------------------------------------+  
| OK                                              |  
+-------------------------------------------------+  
mysql> SET @f = '{ "filter": { "log": false } }';  
mysql> SELECT audit_log_filter_set_filter('SomeFilter', @f);  
+-----------------------------------------------+  
| audit_log_filter_set_filter('SomeFilter', @f) |  
+-----------------------------------------------+  
| OK                                            |  
+-----------------------------------------------+  
mysql> SELECT audit_log_filter_set_user('user1@localhost', 'SomeFilter');  
+------------------------------------------------------------+  
| audit_log_filter_set_user('user1@localhost', 'SomeFilter') |  
+------------------------------------------------------------+  
| OK                                                         |  
+------------------------------------------------------------+  
mysql> SELECT audit_log_read(audit_log_read_bookmark());  
+-----------------------------------------------------------------------+  
| audit_log_read(audit_log_read_bookmark())                             |  
+-----------------------------------------------------------------------+  
| [ {"timestamp":"2020-05-18 22:41:24","id":0,"class":"connection", ... |  
+-----------------------------------------------------------------------+  
mysql> SELECT audit_log_read('null');  
+------------------------+  
| audit_log_read('null') |  
+------------------------+  
| null                   |  
+------------------------+  
mysql> SELECT audit_log_read_bookmark();  
+-------------------------------------------------+  
| audit_log_read_bookmark()                       |  
+-------------------------------------------------+  
| { "timestamp": "2019-10-03 21:03:44", "id": 0 } |  
+-------------------------------------------------+  
Audit Log Option and Variable Reference
Audit Log Options and Variables

This section describes the command options and system variables that configure operation of MySQL Enterprise Audit. If values specified at startup time are incorrect, theaudit_log plugin may fail to initialize properly and the server does not load it. In this case, the server may also produce error messages for other audit log settings because it does not recognize them.

To configure activation of the audit log plugin, use this option:

If the audit log plugin is enabled, it exposes several system variables that permit control over logging:

mysql> SHOW VARIABLES LIKE 'audit_log%';
+--------------------------------------+--------------+
| Variable_name                        | Value        |
+--------------------------------------+--------------+
| audit_log_buffer_size                | 1048576      |
| audit_log_compression                | NONE         |
| audit_log_connection_policy          | ALL          |
| audit_log_current_session            | OFF          |
| audit_log_disable                    | OFF          |
| audit_log_encryption                 | NONE         |
| audit_log_exclude_accounts           |              |
| audit_log_file                       | audit.log    |
| audit_log_filter_id                  | 0            |
| audit_log_flush                      | OFF          |
| audit_log_format                     | NEW          |
| audit_log_format_unix_timestamp      | OFF          |
| audit_log_include_accounts           |              |
| audit_log_policy                     | ALL          |
| audit_log_read_buffer_size           | 32768        |
| audit_log_rotate_on_size             | 0            |
| audit_log_statement_policy           | ALL          |
| audit_log_strategy                   | ASYNCHRONOUS |
+--------------------------------------+--------------+

You can set any of these variables at server startup, and some of them at runtime. Those that are available only for legacy mode audit log filtering are so noted.

Audit Log Status Variables

If the audit log plugin is enabled, it exposes several status variables that provide operational information. These variables are available for legacy mode audit filtering and JSON mode audit filtering.