Percona Audit Log Plugin [repack] May 2026
Check errors:
-- Enable plugin INSTALL PLUGIN audit_log SONAME 'audit_log.so'; -- Configure SET GLOBAL audit_log_format = 'NEW'; SET GLOBAL audit_log_strategy = 'ASYNCHRONOUS'; SET GLOBAL audit_log_rotate_on_size = 52428800; -- 50 MB percona audit log plugin
SET GLOBAL audit_log_exclude_accounts = 'root@localhost,admin@%'; | Problem | Likely cause | Solution | |---------|--------------|----------| | No logs written | Plugin not loaded | SHOW PLUGINS; – if missing, reinstall | | Log file huge | No filters applied | Set audit_log_exclude_commands = 'SHOW,SELECT' etc. | | Performance drop | SYNCHRONOUS strategy | Change to ASYNCHRONOUS | | Rotation not working | audit_log_rotate_on_size = 0 | Set positive value | | Missing JSON format | Using OLD format | Set audit_log_format = 'NEW' | Check errors: -- Enable plugin INSTALL PLUGIN audit_log
| Variable | Description | Example | |----------|-------------|---------| | audit_log_format | OLD (XML), NEW (JSON), CSV | NEW | | audit_log_file | Log file path | /var/log/mysql/audit.log | | audit_log_rotate_on_size | Auto-rotate size in bytes | 104857600 (100MB) | | audit_log_rotations | Number of rotated files to keep | 9 | | audit_log_strategy | ASYNCHRONOUS , PERFORMANCE , SEMISYNCHRONOUS , SYNCHRONOUS | ASYNCHRONOUS | [mysqld] audit_log_format = JSON audit_log_file = /var/log/mysql/audit.log audit_log_rotate_on_size = 104857600 audit_log_rotations = 9 audit_log_strategy = ASYNCHRONOUS audit_log_exclude_accounts = 'root@localhost' 💡 ASYNCHRONOUS gives the best performance. SYNCHRONOUS guarantees logging but slows down queries. 4. Filtering (Most Important Feature) Without filters, audit logs grow enormous. Use audit_log_include_accounts / audit_log_exclude_accounts and audit_log_include_commands / audit_log_exclude_commands . Filter by user account -- Log only 'app_user' and 'replication' SET GLOBAL audit_log_include_accounts = 'app_user@%,replication@%'; -- Exclude 'monitor' and 'backup' users SET GLOBAL audit_log_exclude_accounts = 'monitor@%,backup@%'; Filter by SQL command type -- Log only SELECT, INSERT, UPDATE, DELETE SET GLOBAL audit_log_include_commands = 'SELECT,INSERT,UPDATE,DELETE'; -- Exclude SHOW and SET commands SET GLOBAL audit_log_exclude_commands = 'SHOW,SET'; Filter by database -- Log only activity on 'payments' or 'users' DB SET GLOBAL audit_log_include_databases = 'payments,users'; -- Exclude 'test' and 'tmp' DB SET GLOBAL audit_log_exclude_databases = 'test,tmp'; 🔁 Filters are additive – if you specify both include_commands and exclude_accounts , both are applied. 5. Log Formats JSON (recommended) "audit_record": "timestamp": "2025-03-15T10:23:45 UTC", "user": "app_user[app_user] @ localhost []", "host": "localhost", "command": "INSERT", "sqltext": "INSERT INTO orders VALUES (123, 'pending')", "database": "ecommerce", "status": 0 Filter by user account -- Log only 'app_user'