---
title: "Configure Grafana Alloy for MySQL monitoring | Grafana Labs"
description: "Learn how to configure Grafana Alloy with the MySQL integration snippets to collect metrics and logs from your MySQL database."
---

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

# Configure Grafana Alloy for MySQL monitoring

In this milestone, you configure Grafana Alloy using the configuration snippets provided by the MySQL integration. These snippets enable Grafana Alloy to collect MySQL metrics and logs and send them to your Grafana Cloud instance.

The configuration includes components for MySQL metrics collection using the Prometheus MySQL exporter component and log collection using Loki source file components.

To configure Grafana Alloy for MySQL monitoring, complete the following steps:

1. On the MySQL integration page in Grafana Cloud, scroll to the **Set up Grafana Alloy to use the MySQL integration** section.
2. At the bottom of the snippet, click **Copy to clipboard**.
3. Open the Grafana Alloy configuration file on your system. For example, on a Linux machine, run:
   
   ![Copy code to clipboard](/media/images/icons/icon-copy-small-2.svg) Copy
   
   ```none
   sudo nano /etc/alloy/config.alloy
   ```
4. Paste the integration snippet into the configuration file.
5. Leave `data_source_name` set to `local.file.mysql_secret.content`. The snippet reads the MySQL connection string from a secret file, so the password is not stored in the Alloy configuration.
   
   On the machine where Grafana Alloy runs, create that file with the monitoring user from the previous milestone:
   
   ![Copy code to clipboard](/media/images/icons/icon-copy-small-2.svg) Copy
   
   ```none
   echo -n 'alloy_monitor:secure_password@(localhost:3306)/' > /var/lib/alloy/mysql-secret
   ```
   
   Replace `secure_password` with the password you set for `alloy_monitor`. Replace `localhost:3306` if MySQL is on a different host or port. The file must contain only the connection string, with no trailing newline.
6. Review the log path in the logs configuration and update it if necessary:
   
   - For Linux systems, the default path is `/var/log/mysql/*.log`
   - For Windows systems, the default path is `C:\ProgramData\MySQL\MySQL Server*\Data\*.log`
7. Save the configuration file and exit the editor.
8. Restart the Grafana Alloy service to apply the configuration. On Linux, run:
   
   ![Copy code to clipboard](/media/images/icons/icon-copy-small-2.svg) Copy
   
   ```none
   sudo systemctl restart alloy
   ```
9. Check the service status to ensure it started successfully. On Linux, run:
   
   ![Copy code to clipboard](/media/images/icons/icon-copy-small-2.svg) Copy
   
   ```none
   sudo systemctl status alloy
   ```

The Grafana Alloy service should restart successfully and begin collecting MySQL metrics and logs.

In the next milestone, you test the connection to verify that data is being collected and sent to Grafana Cloud.

* * *

### More to explore (optional)

- [Configure Grafana Alloy to collect all metrics and logs (advanced)](/docs/grafana-cloud/monitor-infrastructure/integrations/integration-reference/integration-linux-node/#advanced-mode)
- [Configure Grafana Alloy](/docs/alloy/latest/configure/)
- [Logs and relabeling basics in Grafana Alloy (tutorial)](/docs/alloy/latest/tutorials/logs-and-relabeling-basics/)
- [Grafana Alloy configuration reference](/docs/alloy/latest/reference/)

Were you successful?

![No](/media/images/svg/thumbs-up.svg) No

![Yes](/media/images/svg/thumbs-up.svg) Yes

Super! You can move to the next step.

* * *

### Troubleshooting

Explore the following troubleshooting topics if you need help:

- [The Alloy configuration file is empty](/docs/grafana-cloud/monitor-infrastructure/integrations/troubleshoot/install-troubleshoot-linux-alloy/#the-alloy-configuration-file-is-empty)
- [Data appears in Grafana Cloud, but hostname is incorrect or it appears as “localhost”](/docs/grafana-cloud/monitor-infrastructure/integrations/troubleshoot/install-troubleshoot-linux-alloy/#data-appears-in-grafana-cloud-but-hostname-is-incorrect-or-it-appears-as-localhost)

Please tell us what didn't work:

Submit

Submitting...

There was an error with your submission.

Thank you!

Need more support? Check out these [helpful resources.](/help/)
