Prepare your MySQL database
In this milestone, you’ll prepare your MySQL database for monitoring. This involves enabling Performance Schema, creating a dedicated monitoring user, and adjusting digest length settings for complete query capture.
To prepare your MySQL database instance for Database Observability, complete the following steps:
Verify that Performance Schema is enabled. It is on by default in MySQL 8.0 and later:
SHOW VARIABLES LIKE 'performance_schema';Expected result: Value is
ON.Create a dedicated monitoring user and replace the password with a strong value:
CREATE USER 'db-o11y'@'%' IDENTIFIED BY '<STRONG_PASSWORD>';Grant the required privileges to the monitoring user:
GRANT PROCESS ON *.* TO 'db-o11y'@'%'; GRANT REPLICATION CLIENT ON *.* TO 'db-o11y'@'%'; GRANT SELECT ON performance_schema.* TO 'db-o11y'@'%';Exclude the monitoring user’s own queries from Performance Schema data:
UPDATE performance_schema.setup_actors SET ENABLED = 'NO', HISTORY = 'NO' WHERE HOST = '%' AND USER = 'db-o11y';Grant object-level privileges for schema details and explain plans:
GRANT SELECT ON *.* TO 'db-o11y'@'%';This lets Alloy collect table schemas, indexes, and run
EXPLAINon sampled queries.Increase the digest length to capture complete query text:
SET GLOBAL max_digest_length = 4096; SET GLOBAL performance_schema_max_digest_length = 4096;Verify both settings:
SHOW VARIABLES LIKE 'max_digest_length'; SHOW VARIABLES LIKE 'performance_schema_max_digest_length';Expected result: Both values are
4096.Note: Add these settings to your MySQL configuration file (
my.cnf) to persist across restarts.Optional: Enable Performance Schema consumers for CPU and wait event data:
UPDATE performance_schema.setup_consumers SET ENABLED = 'YES' WHERE NAME IN ('events_statements_cpu', 'events_waits_current', 'events_waits_history');These consumers reset when MySQL restarts. You can grant Alloy permission to auto-enable them instead — refer to the Database Observability MySQL setup documentation for details.
You’ve prepared your MySQL database for Database Observability monitoring.
In the next milestone, you’ll configure Grafana Alloy with the Database Observability components.