---
title: "Prepare your MySQL database | Grafana Labs"
description: "Enable Performance Schema, create a monitoring user, and configure digest settings for Database Observability."
---

> For a curated documentation index, see [llms.txt](/llms.txt). For the complete documentation index, see [llms-full.txt](/llms-full.txt).

# 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.

01. To prepare your MySQL database instance for Database Observability, complete the following steps:
02. Verify that Performance Schema is enabled. It is on by default in MySQL 8.0 and later:
    
    SQL ![Copy code to clipboard](/media/images/icons/icon-copy-small-2.svg) Copy
    
    ```sql
    SHOW VARIABLES LIKE 'performance_schema';
    ```
    
    Expected result: Value is `ON`.
03. Create a dedicated monitoring user and replace the password with a strong value:
    
    SQL ![Copy code to clipboard](/media/images/icons/icon-copy-small-2.svg) Copy
    
    ```sql
    CREATE USER 'db-o11y'@'%' IDENTIFIED BY '<STRONG_PASSWORD>';
    ```
04. Grant the required privileges to the monitoring user:
    
    SQL ![Copy code to clipboard](/media/images/icons/icon-copy-small-2.svg) Copy
    
    ```sql
    GRANT PROCESS ON *.* TO 'db-o11y'@'%';
    GRANT REPLICATION CLIENT ON *.* TO 'db-o11y'@'%';
    GRANT SELECT ON performance_schema.* TO 'db-o11y'@'%';
    ```
05. Exclude the monitoring user’s own queries from Performance Schema data:
    
    SQL ![Copy code to clipboard](/media/images/icons/icon-copy-small-2.svg) Copy
    
    ```sql
    UPDATE performance_schema.setup_actors
    SET ENABLED = 'NO', HISTORY = 'NO'
    WHERE HOST = '%' AND USER = 'db-o11y';
    ```
06. Grant object-level privileges for schema details and explain plans:
    
    SQL ![Copy code to clipboard](/media/images/icons/icon-copy-small-2.svg) Copy
    
    ```sql
    GRANT SELECT ON *.* TO 'db-o11y'@'%';
    ```
    
    This lets Alloy collect table schemas, indexes, and run `EXPLAIN` on sampled queries.
07. Increase the digest length to capture complete query text:
    
    SQL ![Copy code to clipboard](/media/images/icons/icon-copy-small-2.svg) Copy
    
    ```sql
    SET GLOBAL max_digest_length = 4096;
    SET GLOBAL performance_schema_max_digest_length = 4096;
    ```
08. Verify both settings:
    
    SQL ![Copy code to clipboard](/media/images/icons/icon-copy-small-2.svg) Copy
    
    ```sql
    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.
09. **Optional:** Enable Performance Schema consumers for CPU and wait event data:
    
    SQL ![Copy code to clipboard](/media/images/icons/icon-copy-small-2.svg) Copy
    
    ```sql
    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](/docs/grafana-cloud/monitor-applications/database-observability/set-up/mysql/mysql/) for details.
10. You’ve prepared your MySQL database for Database Observability monitoring.

In the next milestone, you’ll configure Grafana Alloy with the Database Observability components.
