Add default db field to audit log records
Description
~~~~~~~~~~~
Add field `DB' for `MYSQL_
Example old format XML:
,----
| <AUDIT_RECORD
| NAME="Query"
| RECORD=
| TIMESTAMP=
| COMMAND_
| CONNECTION_ID="2"
| STATUS="0"
| SQLTEXT="select 1"
| USER="root[root] @ localhost []"
| HOST="localhost"
| OS_USER=""
| IP=""
| DB="test"
| />
`----
Example JSON:
,----
| {
| "audit_record": {
| "name": "Query",
| "record": "11_2016-
| "timestamp": "2016-06-
| "command_class": "select",
| "connection_id": "1",
| "status": 0,
| "sqltext": "select 1",
| "user": "root[root] @ localhost []",
| "host": "localhost",
| "os_user": "",
| "ip": "",
| "db": "db"
| }
| }
`----
`DB' will be empty for connections which were live upon plugin
installation.
Implementation
~~~~~~~~~~~~~~
Since there is no `db' field for `MYSQL_
we need to keep track of default database changes inside the plugin.
Current database can be set at connection time, with `change user'
command and with `mysql_select_db' command (`COM_INIT_DB').
code
----
- for successful `AUDIT_
`database' value
- for `MYSQL_
capture `general_query' field. Note that `general_query' field is
set only for `MYSQL_
`MYSQL_
`MYSQL_
emitted if `Init DB' failed with error
- query `use db1' changes default database as well. It generates log
event `Query' with `sql_command' `change_db' and query `use db1'
(could be `USE db1' or even `uSe `db`').
- add `DB' to every supported log format as a last field
testing
-------
- create test case executing `create database', `change user',
`connect' with different default database. Record and compare logged
output. Issue is that `mysql_select_db' is not available from test
scenario, but we can probably run mysql cli in batch mode.
- test case should also execute `INSTALL PLUGIN' and `UNINSTALL
PLUGIN' to make sure there is no garbage and no crash when
logging connections which were live upon plugin installation.
- correctness of formatting will be verified by existing `_old',
`_new', `_json' and `_csv' tests.
Blueprint information
- Status:
- Complete
- Approver:
- Laurynas Biveinis
- Priority:
- Medium
- Drafter:
- Sergei Glushchenko
- Direction:
- Approved
- Assignee:
- Sergei Glushchenko
- Definition:
- Approved
- Series goal:
- Accepted for 5.6
- Implementation:
- Implemented
- Milestone target:
- None
- Started by
- Sergei Glushchenko
- Completed by
- Sergei Glushchenko