|
| 1 | +--- |
| 2 | +title: Audit logs for Azure Database for MySQL |
| 3 | +description: Describes the audit logs available in Azure Database for MySQL, and the available parameters for enabling logging levels. |
| 4 | +author: ajlam |
| 5 | +ms.author: andrela |
| 6 | +ms.service: mysql |
| 7 | +ms.topic: conceptual |
| 8 | +ms.date: 06/11/2019 |
| 9 | +--- |
| 10 | + |
| 11 | +# Audit Logs in Azure Database for MySQL |
| 12 | + |
| 13 | +In Azure Database for MySQL, the audit log is available to users. The audit log can be used to track database-level activity and is commonly used for compliance. |
| 14 | + |
| 15 | +> [!IMPORTANT] |
| 16 | +> Audit log functionality is currently in preview. |
| 17 | +
|
| 18 | +## Configure audit logging |
| 19 | + |
| 20 | +By default the audit log is disabled. To enable it, set `audit_log_enabled` to ON. |
| 21 | + |
| 22 | +Other parameters you can adjust include: |
| 23 | + |
| 24 | +- `audit_log_events`: controls the events to be logged. See below table for specific audit events. |
| 25 | +- `audit_log_exclude_users`: MySQL users to be excluded from logging. Allows for at most four users. Max length of the parameter is 256 characters. |
| 26 | + |
| 27 | +| **Event** | **Description** | |
| 28 | +|---|---| |
| 29 | +| `CONNECTION` | - Connection initiation (successful or unsuccessful) <br> - User reauthentication with different user/password during session <br> - Connection termination | |
| 30 | +| `DML_SELECT`| SELECT queries | |
| 31 | +| `DML_NONSELECT` | INSERT/DELETE/UPDATE queries | |
| 32 | +| `DML` | DML = DML_SELECT + DML_NONSELECT | |
| 33 | +| `DDL` | Queries like "DROP DATABASE" | |
| 34 | +| `DCL` | Queries like "GRANT PERMISSION" |s |
| 35 | +| `ADMIN` | Queries like "SHOW STATUS" | |
| 36 | +| `GENERAL` | All in DML_SELECT, DML_NONSELECT, DML, DDL, DCL, and ADMIN | |
| 37 | +| `TABLE_ACCESS` | - Only available for MySQL 5.7 <br> - Table read statements, such as SELECT or INSERT INTO ... SELECT <br> - Table delete statements, such as DELETE or TRUNCATE TABLE <br> - Table insert statements, such as INSERT or REPLACE <br> - Table update statements, such as UPDATE | |
| 38 | + |
| 39 | +## Access audit logs |
| 40 | + |
| 41 | +Audit logs are integrated with Azure Monitor Diagnostic Logs. Once you've enabled audit logs on your MySQL server, you can emit them to Azure Monitor logs, Event Hubs, or Azure Storage. To learn more about how to enable diagnostic logs in the Azure portal, see the [audit log portal article](howto-configure-audit-logs-portal.md#set-up-diagnostic-logs). |
| 42 | + |
| 43 | +## Schemas |
| 44 | + |
| 45 | +The following sections describe what's output by MySQL audit logs based on the event type. Depending on the output method, the fields included and the order in which they appear may vary. |
| 46 | + |
| 47 | +### Connection |
| 48 | + |
| 49 | +| **Property** | **Description** | |
| 50 | +|---|---| |
| 51 | +| `TenantId` | Your tenant ID | |
| 52 | +| `SourceSystem` | `Azure` | |
| 53 | +| `TimeGenerated` [UTC] | Time stamp when the log was recorded in UTC | |
| 54 | +| `Type` | Type of the log. Always `AzureDiagnostics` | |
| 55 | +| `SubscriptionId` | GUID for the subscription that the server belongs to | |
| 56 | +| `ResourceGroup` | Name of the resource group the server belongs to | |
| 57 | +| `ResourceProvider` | Name of the resource provider. Always `MICROSOFT.DBFORMYSQL` | |
| 58 | +| `ResourceType` | `Servers` | |
| 59 | +| `ResourceId` | Resource URI | |
| 60 | +| `Resource` | Name of the server | |
| 61 | +| `Category` | `MySqlAuditLogs` | |
| 62 | +| `OperationName` | `LogEvent` | |
| 63 | +| `event_class` | `connection_log` | |
| 64 | +| `event_subclass` | `CONNECT`, `DISCONNECT`, `CHANGE USER` (only available for MySQL 5.7) | |
| 65 | +| `connection_id` | Unique connection ID generated by MySQL | |
| 66 | +| `host` | Blank | |
| 67 | +| `ip` | IP address of client connecting to MySQL | |
| 68 | +| `user` | Name of user executing the query | |
| 69 | +| `db` | Name of database connected to | |
| 70 | +| `\_ResourceId` | Resource URI | |
| 71 | + |
| 72 | +### General |
| 73 | + |
| 74 | +Schema below applies to GENERAL, DML_SELECT, DML_NONSELECT, DML, DDL, DCL, and ADMIN event types. |
| 75 | + |
| 76 | +| **Property** | **Description** | |
| 77 | +|---|---| |
| 78 | +| `TenantId` | Your tenant ID | |
| 79 | +| `SourceSystem` | `Azure` | |
| 80 | +| `TimeGenerated` [UTC] | Time stamp when the log was recorded in UTC | |
| 81 | +| `Type` | Type of the log. Always `AzureDiagnostics` | |
| 82 | +| `SubscriptionId` | GUID for the subscription that the server belongs to | |
| 83 | +| `ResourceGroup` | Name of the resource group the server belongs to | |
| 84 | +| `ResourceProvider` | Name of the resource provider. Always `MICROSOFT.DBFORMYSQL` | |
| 85 | +| `ResourceType` | `Servers` | |
| 86 | +| `ResourceId` | Resource URI | |
| 87 | +| `Resource` | Name of the server | |
| 88 | +| `Category` | `MySqlAuditLogs` | |
| 89 | +| `OperationName` | `LogEvent` | |
| 90 | +| `event_class` | `general_log` | |
| 91 | +| `event_subclass` | `LOG`, `ERROR`, `RESULT` (only available for MySQL 5.6) | |
| 92 | +| `event_time` | Query start seconds in UNIX timestamp | |
| 93 | +| `error_code` | Error code if query failed. `0` means no error | |
| 94 | +| `thread_id` | ID of thread that executed the query | |
| 95 | +| `host` | Blank | |
| 96 | +| `ip` | IP address of client connecting to MySQL | |
| 97 | +| `user` | Name of user executing the query | |
| 98 | +| `sql_text` | Full query text | |
| 99 | +| `\_ResourceId` | Resource URI | |
| 100 | + |
| 101 | +### Table access |
| 102 | + |
| 103 | +| **Property** | **Description** | |
| 104 | +|---|---| |
| 105 | +| `TenantId` | Your tenant ID | |
| 106 | +| `SourceSystem` | `Azure` | |
| 107 | +| `TimeGenerated` [UTC] | Time stamp when the log was recorded in UTC | |
| 108 | +| `Type` | Type of the log. Always `AzureDiagnostics` | |
| 109 | +| `SubscriptionId` | GUID for the subscription that the server belongs to | |
| 110 | +| `ResourceGroup` | Name of the resource group the server belongs to | |
| 111 | +| `ResourceProvider` | Name of the resource provider. Always `MICROSOFT.DBFORMYSQL` | |
| 112 | +| `ResourceType` | `Servers` | |
| 113 | +| `ResourceId` | Resource URI | |
| 114 | +| `Resource` | Name of the server | |
| 115 | +| `Category` | `MySqlAuditLogs` | |
| 116 | +| `OperationName` | `LogEvent` | |
| 117 | +| `event_class` | `table_access_log` | |
| 118 | +| `event_subclass` | `READ`, `INSERT`, `UPDATE`, or `DELETE` | |
| 119 | +| `connection_id` | Unique connection ID generated by MySQL | |
| 120 | +| `db` | Name of database accessed | |
| 121 | +| `table` | Name of table accessed | |
| 122 | +| `sql_text` | Full query text | |
| 123 | +| `\_ResourceId` | Resource URI | |
| 124 | + |
| 125 | +## Next steps |
| 126 | + |
| 127 | +- [How to configure audit logs in the Azure portal](howto-configure-audit-logs-portal.md) |
0 commit comments