Skip to content

Commit

Permalink
Merge pull request #455 from percona/9653
Browse files Browse the repository at this point in the history
PS-9653 [DOCS] - Add audit_log_filter set_filter examples 8.4
  • Loading branch information
patrickbirch authored Jan 30, 2025
2 parents a21847c + 90fed10 commit c07baac
Show file tree
Hide file tree
Showing 4 changed files with 616 additions and 6 deletions.
143 changes: 140 additions & 3 deletions docs/filter-audit-log-filter-files.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,144 @@ The default account is represented by `%` as the account name.

You can assign filters to a specific user account or disassociate a user account from a filter. To disassociate a user account, either unassign a filter or assign a different filter. If you remove a filter, that filter is unassigned from all users, including current users in current sessions.




## set_filter options and available filters

| Filter | Available options |
|------------------|-----------------------------------------------------------------------------------|
| class Filter | `general`: Logs general server events |
| | `connection`: Tracks connection-related activities |
| | `table_access`: Monitors database table interactions |
| user Filter | Accepts specific usernames as filter criteria |
| | Can include multiple usernames |
| | Supports wildcard matching |
| database Filter | Filters events by database name |
| | Accepts exact database names |
| | Supports wildcard matching for database selection |
| table Filter | Specifies individual table names |
| | Allows filtering for specific tables within databases |
| | Supports wildcard matching |
| operation Filter | `read`: SELECT statements |
| | `write`: INSERT, UPDATE, DELETE statements |
| | `ddl`: Data Definition Language operations |
| | `dcl`: Data Control Language operations |
| event Filter | `status`: Tracks query execution status |
| | `query`: Captures query details |
| | `connection`: Monitors connection events |
| status Filter | `0`: Successful operations |
| | `1`: Failed operations |

### Examples

Create simple filters

```{.bash data-prompt="mysql>"}
mysql> SELECT audit_log_filter_set_filter('log_general', '{
"filter": {
"class": {
"name": "general"
}
}
}');

mysql> SELECT audit_log_filter_set_filter('log_connection', '{
"filter": {
"class": {
"name": "connection"
}
}
}');

mysql> SELECT audit_log_filter_set_filter('log_table_access', '{
"filter": {
"class": {
"name": "table_access"
}
}
}');

mysql> SELECT audit_log_filter_set_filter('log_global_variable', '{
"filter": {
"class": {
"name": "global_variable"
}
}
}');

mysql> SELECT audit_log_filter_set_filter('log_command', '{
"filter": {
"class": {
"name": "command"
}
}
}');

mysql> SELECT audit_log_filter_set_filter('log_query', '{
"filter": {
"class": {
"name": "query"
}
}
}');

mysql> SELECT audit_log_filter_set_filter('log_stored_program', '{
"filter": {
"class": {
"name": "stored_program"
}
}
}');

mysql> SELECT audit_log_filter_set_filter('log_authentication', '{
"filter": {
"class": {
"name": "authentication"
}
}
}');

mysql> SELECT audit_log_filter_set_filter('log_message', '{
"filter": {
"class": {
"name": "message"
}
}
}');
```

Add filter_update_on_user_change.

```{.bash data-prompt="mysql>"}
mysql> SELECT audit_log_filter_set_filter('log_connect', '{
"filter": {
"class": {
"name": "connection",
"event": {
"name": "connect"
}
}
}
}');

mysql> SELECT audit_log_filter_set_filter('log_disconnect', '{
"filter": {
"class": {
"name": "connection",
"event": {
"name": "disconnect"
}
}
}
}');
```

| Option | Filters | Example | Event |
|-------------|---------------------------------------------|--------------------------------|-------------------------------------------|
| class | general, connection, table_access | N/A | general: Server-wide events, query processing<br>connection: Login, logout, connection attempts<br>table_access: Database and table-level interactions |
| user | Filters by MySQL user accounts | ["admin", "readonly_user"] | All actions performed by specified users |
| database | Filters by database name | ["sales", "inventory"] | Operations within specified databases |
| table | Filters by table name | ["customers", "orders"] | Interactions with specific tables |
| operation | For table_access: read, insert, update, delete<br>For connection: connect, disconnect | N/A | Specific types of database operations |
| status | 0: Successful queries<br>1: Failed queries | N/A | Query execution result filtering |
| thread_id | Filters by specific MySQL thread identifiers | ["12345", "67890"] | Actions within a particular database thread |
| query_time | Filters based on query execution duration | N/A | Long-running or quick queries |

67 changes: 64 additions & 3 deletions docs/json-overview.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,67 @@
# JSON in MySQL
# JSON in Percona Server for MySQL

JSON stands for JavaScript Object Notation. It is a lightweight data-interchange format that is easy for humans to read and write. It is also easy for machines to parse and generate. Percona Server for MySQL supports JSON data type, allowing you to store JSON documents in your database.

The JSON data type in Percona Server for MySQL is a handy way to store and work with flexible, semi-structured data right in your database. Think of it as a way to save JSON objects directly into your tables, so you don’t have to convert them into a rigid format.

When you use the JSON data type, the database stores your data in a special binary format that’s optimized for speed and space which is faster and more efficient than just saving JSON as plain text.

The JSON data type is great when your data doesn’t fit into a fixed structure or if it’s likely to change over time. The following are examples of when you would use the JSON data type:

* Storing user preferences or settings.

* Capturing logs or other dynamic data.

* Handling complex objects without adding a ton of columns to your table.

JSON has the following features:

<style>
table {
width: 100%;
border-collapse: collapse;
}
th, td {
border: 1px solid #ccc;
padding: 8px;
text-align: left;
}
th:first-child, td:first-child {
width: auto;
white-space: nowrap;
}
</style>

| Feature | Details |
|----------------------|-----------------------------------------------------------------------------------------------------------------------|
| Validation Built-In | Percona Server checks your JSON data when you insert or update it to make sure it’s valid. If something’s wrong, you’ll know right away. |
| Powerful Querying | You can dig into specific parts of your JSON data using built-in functions like the following: <br> - `JSON_EXTRACT()` to pull out specific keys or values. <br> - `JSON_CONTAINS()` to check if a key or value exists. <br> - `JSON_SET()` to update parts of your JSON object without replacing the whole thing. |
| Indexing for Speed | If you often query a particular key inside your JSON, you can create a generated column based on that key and index it, making queries much faster. |

## Use JSON in your database

The following is an example using JSON in your database.

```JSON
CREATE TABLE user_data (
id INT PRIMARY KEY AUTO_INCREMENT,
name VARCHAR(50),
settings JSON
);

INSERT INTO user_data (name, settings)
VALUES ('John', '{"theme": "dark", "notifications": {"email": true, "sms": false}}');

SELECT JSON_EXTRACT(settings, '$.theme') AS theme
FROM user_data
WHERE name = 'John';
```

* The settings column stores JSON data.

* You can use `JSON_EXTRACT()` to get the value of a specific key, like theme.

JSON stands for JavaScript Object Notation. It is a lightweight data-interchange format that is easy for humans to read and write. It is also easy for machines to parse and generate. MySQL supports JSON data type, allowing you to store JSON documents in your database.
JSON in Percona Server for MySQL gives you have the flexibility of NoSQL with the reliability and querying power of a relational database.

## Create a table with JSON Data Type

Expand Down Expand Up @@ -81,7 +142,7 @@ WHERE name = 'John Doe';

## Use JSON Functions

MySQL provides several functions to work with JSON data.
Percona Server for MySQL provides several functions to work with JSON data.

### `JSON_EXTRACT`

Expand Down
Loading

0 comments on commit c07baac

Please sign in to comment.