Query Logging
Overview
ProxySQL enables comprehensive query logging, capturing SQL statements processed through the proxy for analysis and monitoring purposes. Logging can be applied globally or selectively by query pattern, username, or other rule criteria.
Basic Setup
Enable logging by setting the log filename:
SET mysql-eventslog_filename='queries.log';
LOAD MYSQL VARIABLES TO RUNTIME;
SAVE MYSQL VARIABLES TO DISK;
To log all queries globally:
SET mysql-eventslog_default_log=1;
LOAD MYSQL VARIABLES TO RUNTIME;
SAVE MYSQL VARIABLES TO DISK;
Selective Logging
By username:
INSERT INTO mysql_query_rules (rule_id, active, username, log, apply)
VALUES (1, 1, 'Bob', 1, 0);
By query pattern:
INSERT INTO mysql_query_rules (rule_id, active, match_digest, log, apply)
VALUES (1, 1, 'INSERT.*tableX', 1, 0);
Log Format
Controlled via mysql-eventslog_format (available from version 2.0.6):
| Value | Format |
|---|---|
1 | Binary (default) |
2 | JSON |
JSON log entries include: client IP, digest hash, duration, timestamps, hostgroup ID, query text, rows affected/sent, schema, username, and event type.
SET mysql-eventslog_format=2;
LOAD MYSQL VARIABLES TO RUNTIME;
SAVE MYSQL VARIABLES TO DISK;