diff --git a/docs/sources/collect/mysql-database-metrics.md b/docs/sources/collect/mysql-database-metrics.md new file mode 100644 index 00000000000..d501c153765 --- /dev/null +++ b/docs/sources/collect/mysql-database-metrics.md @@ -0,0 +1,304 @@ +--- +canonical: https://grafana.com/docs/alloy/latest/collect/mysql-database-metrics/ +description: Learn how to collect MySQL database metrics and logs with Grafana Alloy. +title: Collect MySQL database metrics and logs +weight: 410 +labels: + products: + - oss +review_date: 2026-07-30 +--- + +# Collect MySQL database metrics and logs + +You can configure {{< param "PRODUCT_NAME" >}} to collect database observability data from MySQL servers including metrics, logs, and performance schema statistics. +Forward this data to Grafana Cloud, Prometheus, Loki, or any compatible observability backend. + +You can accomplish the following with {{< param "PRODUCT_NAME" >}}: + +* Collect query performance data, explain plans, and lock information from MySQL. +* Monitor schema and table statistics. +* Forward database observability logs to Loki. +* Scrape MySQL metrics with Prometheus. + +## Components used in this topic + +* [`database_observability.mysql`][database_observability.mysql] +* [`prometheus.exporter.mysql`][prometheus.exporter.mysql] +* [`loki.relabel`][loki.relabel] +* [`discovery.relabel`][discovery.relabel] +* [`prometheus.scrape`][prometheus.scrape] +* [`prometheus.remote_write`][prometheus.remote_write] +* [`loki.write`][loki.write] + +## Before you begin + +* Ensure you have a running MySQL server with access credentials. +* Enable the MySQL `performance_schema` on your MySQL server. + Refer to the [MySQL performance_schema documentation](https://dev.mysql.com/doc/refman/8.0/en/performance-schema.html) for setup instructions. +* Have write access to a Prometheus-compatible endpoint or Grafana Cloud for storing metrics. +* Have write access to a Loki-compatible endpoint or Grafana Cloud for storing logs. +* Be familiar with the concept of [Components][] in {{< param "PRODUCT_NAME" >}}. + +## Collect MySQL database observability data + +The `database_observability.mysql` component connects to a MySQL database and collects performance schema data. +This data includes query details, execution plans, and lock information forwarded as logs to Loki. +The component also exports targets that can be scraped with Prometheus to collect MySQL metrics. + +To collect MySQL observability data and forward it to Grafana Cloud, complete the following steps: + +1. Add a `database_observability.mysql` component to your configuration file. + + ```alloy + database_observability.mysql "