---
title: "MySQL integration | Grafana Cloud documentation"
description: "Learn about MySQL Grafana Cloud integration."
---

# MySQL integration for Grafana Cloud

MySQL is a managed, open source relational database that is a widely used for both small and large applications.

This integration includes 15 useful alerts and 2 pre-built dashboards to help monitor and visualize MySQL metrics and logs.

## Before you begin

A running MySQL instance, user and password are required for the integration.

Supported versions:

- MySQL &gt;= 5.6
- MariaDB &gt;= 10.2

We recommend that you configure a separate user for Alloy, and give it only the strictly mandatory security privileges necessary for monitoring your node, as per the [official documentation](https://github.com/prometheus/mysqld_exporter#required-grants).

## Install MySQL integration for Grafana Cloud

1. In your Grafana Cloud stack, click **Connections** in the left-hand menu.
2. Find **MySQL** and click its tile to open the integration.
3. Review the prerequisites in the **Configuration Details** tab and set up Grafana Alloy to send MySQL metrics and logs to your Grafana Cloud instance.
4. Click **Install** to add this integration’s pre-built dashboards and alerts to your Grafana Cloud instance, and you can start monitoring your MySQL setup.

## Configuration snippets for Grafana Alloy

### Simple mode

These snippets are configured to scrape a single MySQL node with Grafana Alloy running locally.

Copy and Paste the following snippets into your Grafana Alloy configuration file.

Replace `data_source_name` value to your MySQL DSN connection details. It must follow the URI patterns defined in [go-sql-driver README](https://github.com/go-sql-driver/mysql#dsn-data-source-name), which is `[username[:password]@][protocol[(address)]]/dbname[?param1=value1&...&paramN=valueN]`.

If your MySQL server requires authentication, check the [integration documentation](/docs/grafana-cloud/data-configuration/integrations/integration-reference/integration-mysql/) to understand how to setup a secret file.

### Integrations snippets

Alloy ![Copy code to clipboard](/media/images/icons/icon-copy-small-2.svg) Copy

```alloy
prometheus.exporter.mysql "integrations_mysqld_exporter" {
  data_source_name = "root:password@(localhost:3306)/"
}

discovery.relabel "integrations_mysqld_exporter" {
  targets = prometheus.exporter.mysql.integrations_mysqld_exporter.targets

  rule {
    target_label = "job"
    replacement  = "integrations/mysql"
  }

  rule {
    target_label = "instance"
    replacement  = constants.hostname
  }
}

prometheus.scrape "integrations_mysqld_exporter" {
  targets    = discovery.relabel.integrations_mysqld_exporter.output
  forward_to = [prometheus.remote_write.metrics_service.receiver]
  job_name   = "integrations/mysqld_exporter"
}
```

### Logs snippets

#### darwin

Alloy ![Copy code to clipboard](/media/images/icons/icon-copy-small-2.svg) Copy

```alloy
local.file_match "logs_integrations_mysql" {
  path_targets = [{
    __address__ = "localhost",
    __path__    = "/var/log/mysql/*.log",
    instance    = constants.hostname,
    job         = "integrations/mysql",
  }]
}

loki.process "logs_integrations_mysql" {
  forward_to = [loki.write.grafana_cloud_loki.receiver]

  stage.regex {
    expression = "(?P<timestamp>.+) (?P<thread>[\\d]+) \\[(?P<label>.+?)\\]( \\[(?P<err_code>.+?)\\] \\[(?P<subsystem>.+?)\\])? (?P<msg>.+)"
  }

  stage.labels {
    values = {
      err_code  = null,
      level     = "label",
      subsystem = null,
    }
  }

  stage.drop {
    drop_counter_reason = "drop empty lines"
    expression          = "^ *$"
  }
}

loki.source.file "logs_integrations_mysql" {
  targets    = local.file_match.logs_integrations_mysql.targets
  forward_to = [loki.process.logs_integrations_mysql.receiver]
}
```

#### linux

Alloy ![Copy code to clipboard](/media/images/icons/icon-copy-small-2.svg) Copy

```alloy
local.file_match "logs_integrations_mysql" {
  path_targets = [{
    __address__ = "localhost",
    __path__    = "/var/log/mysql/*.log",
    instance    = constants.hostname,
    job         = "integrations/mysql",
  }]
}

loki.process "logs_integrations_mysql" {
  forward_to = [loki.write.grafana_cloud_loki.receiver]

  stage.regex {
    expression = "(?P<timestamp>.+) (?P<thread>[\\d]+) \\[(?P<label>.+?)\\]( \\[(?P<err_code>.+?)\\] \\[(?P<subsystem>.+?)\\])? (?P<msg>.+)"
  }

  stage.labels {
    values = {
      err_code  = null,
      level     = "label",
      subsystem = null,
    }
  }

  stage.drop {
    drop_counter_reason = "drop empty lines"
    expression          = "^ *$"
  }
}

loki.source.file "logs_integrations_mysql" {
  targets    = local.file_match.logs_integrations_mysql.targets
  forward_to = [loki.process.logs_integrations_mysql.receiver]
}
```

#### windows

Alloy ![Copy code to clipboard](/media/images/icons/icon-copy-small-2.svg) Copy

```alloy
local.file_match "logs_integrations_mysql" {
  path_targets = [{
    __address__ = "localhost",
    __path__    = "C:\ProgramData\MySQL\MySQL Server*\Data\*.log",
    instance    = constants.hostname,
    job         = "integrations/mysql",
  }]
}

loki.process "logs_integrations_mysql" {
  forward_to = [loki.write.grafana_cloud_loki.receiver]

  stage.regex {
    expression = "(?P<timestamp>.+) (?P<thread>[\\d]+) \\[(?P<label>.+?)\\]( \\[(?P<err_code>.+?)\\] \\[(?P<subsystem>.+?)\\])? (?P<msg>.+)"
  }

  stage.labels {
    values = {
      err_code  = null,
      level     = "label",
      subsystem = null,
    }
  }

  stage.drop {
    drop_counter_reason = "drop empty lines"
    expression          = "^ *$"
  }
}

loki.source.file "logs_integrations_mysql" {
  targets    = local.file_match.logs_integrations_mysql.targets
  forward_to = [loki.process.logs_integrations_mysql.receiver]
}
```

### Advanced mode

The following snippets provide examples to guide you through the configuration process.

To instruct Grafana Alloy to scrape your MySQL server, **manually** copy and append the snippets to your alloy configuration file, then follow subsequent instructions.

### Advanced integrations snippets

Alloy ![Copy code to clipboard](/media/images/icons/icon-copy-small-2.svg) Copy

```alloy
local.file "mysql_secret" {
  filename = "/var/lib/alloy/mysql-secret"
  is_secret = true
}

prometheus.exporter.mysql "integrations_mysqld_exporter" {
  data_source_name = local.file.mysql_secret.content
}

discovery.relabel "integrations_mysqld_exporter" {
  targets = prometheus.exporter.mysql.integrations_mysqld_exporter.targets

  rule {
    target_label = "job"
    replacement  = "integrations/mysql"
  }

  rule {
    target_label = "instance"
    replacement  = constants.hostname
  }
}

prometheus.scrape "integrations_mysqld_exporter" {
  targets    = discovery.relabel.integrations_mysqld_exporter.output
  forward_to = [prometheus.remote_write.metrics_service.receiver]
  job_name   = "integrations/mysqld_exporter"
}
```

This integration uses the [prometheus.exporter.mysql](/docs/alloy/latest/reference/components/prometheus.exporter.mysql/) component to collect metrics from a MySQL instance.

For better security, your DSN containing authentication details will be stored in a file, and loaded by Grafana Alloy as a secret. The snippets are prepared to read from `/var/lib/alloy/mysql-secret`. It must follow the URI patterns defined in [go-sql-driver README](https://github.com/go-sql-driver/mysql#dsn-data-source-name), which is `[username[:password]@][protocol[(address)]]/dbname[?param1=value1&...&paramN=valueN]`.

You can create this file using the following command; `echo -n 'user:password@(hostname:3306)/' > /var/lib/alloy/mysql-secret`

For the full array of options included within this exporter, please check the component documentation.

This exporter must be linked with a [discovery.relabel](/docs/alloy/latest/reference/components/discovery.relabel) component to apply the necessary relabelings. For each MySQL instance to be monitored you must create a pair of these components.

The snippets set the `instance` label to your Grafana Alloy server hostname using the `constants.hostname` variable. If you are running Grafana Alloy outside of your MySQL server host, change the variable to a value that uniquely identifies it.

You can then scrape them by including each `discovery.relabel` under `targets` within the `prometheus.scrape` component.

### Advanced logs snippets

#### darwin

Alloy ![Copy code to clipboard](/media/images/icons/icon-copy-small-2.svg) Copy

```alloy
local.file_match "logs_integrations_mysql" {
  path_targets = [{
    __address__ = "localhost",
    __path__    = "/var/log/mysql/*.log",
    instance    = constants.hostname,
    job         = "integrations/mysql",
  }]
}

loki.process "logs_integrations_mysql" {
  forward_to = [loki.write.grafana_cloud_loki.receiver]

  stage.regex {
    expression = "(?P<timestamp>.+) (?P<thread>[\\d]+) \\[(?P<label>.+?)\\]( \\[(?P<err_code>.+?)\\] \\[(?P<subsystem>.+?)\\])? (?P<msg>.+)"
  }

  stage.labels {
    values = {
      err_code  = null,
      level     = "label",
      subsystem = null,
    }
  }

  stage.drop {
    drop_counter_reason = "drop empty lines"
    expression          = "^ *$"
  }
}

loki.source.file "logs_integrations_mysql" {
  targets    = local.file_match.logs_integrations_mysql.targets
  forward_to = [loki.process.logs_integrations_mysql.receiver]
}
```

To collect your MySQL Server logs, you must use a [local.file\_match](/docs/alloy/latest/reference/components/local.file_match/) component to tag the file to be scraped, a [loki.source.file](/docs/alloy/latest/reference/components/loki.source.file/) component to prepare it for Loki ingestion and a [loki.process](/docs/alloy/latest/reference/components/loki.process/) component to process your logs with adequate labels and drop empty lines.

You can check the full array of options in each component documentation.

#### linux

Alloy ![Copy code to clipboard](/media/images/icons/icon-copy-small-2.svg) Copy

```alloy
local.file_match "logs_integrations_mysql" {
  path_targets = [{
    __address__ = "localhost",
    __path__    = "/var/log/mysql/*.log",
    instance    = constants.hostname,
    job         = "integrations/mysql",
  }]
}

loki.process "logs_integrations_mysql" {
  forward_to = [loki.write.grafana_cloud_loki.receiver]

  stage.regex {
    expression = "(?P<timestamp>.+) (?P<thread>[\\d]+) \\[(?P<label>.+?)\\]( \\[(?P<err_code>.+?)\\] \\[(?P<subsystem>.+?)\\])? (?P<msg>.+)"
  }

  stage.labels {
    values = {
      err_code  = null,
      level     = "label",
      subsystem = null,
    }
  }

  stage.drop {
    drop_counter_reason = "drop empty lines"
    expression          = "^ *$"
  }
}

loki.source.file "logs_integrations_mysql" {
  targets    = local.file_match.logs_integrations_mysql.targets
  forward_to = [loki.process.logs_integrations_mysql.receiver]
}
```

To collect your MySQL Server logs, you must use a [local.file\_match](/docs/alloy/latest/reference/components/local.file_match/) component to tag the file to be scraped, a [loki.source.file](/docs/alloy/latest/reference/components/loki.source.file/) component to prepare it for Loki ingestion and a [loki.process](/docs/alloy/latest/reference/components/loki.process/) component to process your logs with adequate labels and drop empty lines.

You can check the full array of options in each component documentation.

#### windows

Alloy ![Copy code to clipboard](/media/images/icons/icon-copy-small-2.svg) Copy

```alloy
local.file_match "logs_integrations_mysql" {
  path_targets = [{
    __address__ = "localhost",
    __path__    = "C:\ProgramData\MySQL\MySQL Server*\Data\*.log",
    instance    = constants.hostname,
    job         = "integrations/mysql",
  }]
}

loki.process "logs_integrations_mysql" {
  forward_to = [loki.write.grafana_cloud_loki.receiver]

  stage.regex {
    expression = "(?P<timestamp>.+) (?P<thread>[\\d]+) \\[(?P<label>.+?)\\]( \\[(?P<err_code>.+?)\\] \\[(?P<subsystem>.+?)\\])? (?P<msg>.+)"
  }

  stage.labels {
    values = {
      err_code  = null,
      level     = "label",
      subsystem = null,
    }
  }

  stage.drop {
    drop_counter_reason = "drop empty lines"
    expression          = "^ *$"
  }
}

loki.source.file "logs_integrations_mysql" {
  targets    = local.file_match.logs_integrations_mysql.targets
  forward_to = [loki.process.logs_integrations_mysql.receiver]
}
```

To collect your MySQL Server logs, you must use a [local.file\_match](/docs/alloy/latest/reference/components/local.file_match/) component to tag the file to be scraped, a [loki.source.file](/docs/alloy/latest/reference/components/loki.source.file/) component to prepare it for Loki ingestion and a [loki.process](/docs/alloy/latest/reference/components/loki.process/) component to process your logs with adequate labels and drop empty lines.

You can check the full array of options in each component documentation.

## Kubernetes instructions

Instructions for Kubernetes

### Before you begin with Kubernetes

These instructions assume the use of the Kubernetes Monitoring Helm chart.  
Please see official [documentation](/docs/grafana-cloud/monitor-infrastructure/kubernetes-monitoring/configuration/helm-chart-config/) for the Helm chart deployment guide.

### Configuration snippets for Kubernetes Helm chart

To scrape MySQL logs and metrics, modify your Kubernetes Monitoring Helm chart with these configuration snippets.

Replace any values between the angle brackets `<>` in the provided snippets with your desired configuration values.

#### Metrics snippets

Alloy ![Copy code to clipboard](/media/images/icons/icon-copy-small-2.svg) Copy

```alloy
integrations:
  mysql:
    instances:
      - name: mysql
        metrics:
          enabled: true
        exporter:
          dataSource:
            host: <your_mysql_service_address>
            auth:
              username: "<your_mysql_root_username>"
              password: "<your_mysql_root_password>"
```

#### Logs snippets

Alloy ![Copy code to clipboard](/media/images/icons/icon-copy-small-2.svg) Copy

```alloy
integrations:
  mysql:
    instances:
      - name: mysql
        logs:
          enabled: true
          labelSelectors:
            <mysql-pod-label>: <mysql-pod-label-value>
podLogs:
  enabled: true
```

## Dashboards

The MySQL integration installs the following dashboards in your Grafana Cloud instance to help monitor your system.

- MySQL
- MySQL logs

**MySQL overview**

**MySQL logs**

## Alerts

The MySQL integration includes the following useful alerts:

Expand table

| Alert                                | Description                                                  |
|--------------------------------------|--------------------------------------------------------------|
| MySQLDown                            | Critical: MySQL not up.                                      |
| MySQLGaleraDonorFallingBehind        | Warning: XtraDB cluster donor node falling behind.           |
| MySQLGaleraNotReady                  | Warning: Galera cluster node not ready.                      |
| MySQLGaleraOutOfSync                 | Warning: Galera cluster node out of sync.                    |
| MySQLHeartbeatLag                    | Critical: MySQL heartbeat is lagging.                        |
| MySQLInnoDBLogWaits                  | Warning: MySQL innodb log writes stalling.                   |
| MySQLInsufficientBinLogCacheSize     | Warning: MySQL binary log cache size insufficient.           |
| MySQLInsufficientBinLogStmtCacheSize | Warning: MySQL binary log statement cache size insufficient. |
| MySQLInsufficientTempTableSize       | Warning: MySQL temp table size insufficient.                 |
| MySQLReplicationLag                  | Critical: MySQL slave replication is lagging.                |
| MySQLReplicationNotRunning           | Critical: Replication is not running.                        |
| MySQLRestarted                       | Critical: MySQL restarted.                                   |
| MySQLSlaveBehindMaster               | Warning: MySQL innodb slave behind master.                   |
| MySQLSlowQueries                     | Warning: MySQL slow queries.                                 |
| MySQLTuneThreadCacheSize             | Warning: MySQL thread cache needs tuning.                    |

## Metrics

The most important metrics provided by the MySQL integration, which are used on the pre-built dashboards and Prometheus alerts, are as follows:

- instance:mysql\_heartbeat\_lag\_seconds
- instance:mysql\_slave\_lag\_seconds
- mysql\_global\_status\_aborted\_clients
- mysql\_global\_status\_aborted\_connects
- mysql\_global\_status\_binlog\_cache\_disk\_use
- mysql\_global\_status\_binlog\_cache\_use
- mysql\_global\_status\_binlog\_stmt\_cache\_disk\_use
- mysql\_global\_status\_binlog\_stmt\_cache\_use
- mysql\_global\_status\_buffer\_pool\_pages
- mysql\_global\_status\_bytes\_received
- mysql\_global\_status\_bytes\_sent
- mysql\_global\_status\_commands\_total
- mysql\_global\_status\_connections
- mysql\_global\_status\_created\_tmp\_disk\_tables
- mysql\_global\_status\_created\_tmp\_files
- mysql\_global\_status\_created\_tmp\_tables
- mysql\_global\_status\_handlers\_total
- mysql\_global\_status\_innodb\_buffer\_pool\_bytes\_data
- mysql\_global\_status\_innodb\_data\_read
- mysql\_global\_status\_innodb\_data\_written
- mysql\_global\_status\_innodb\_log\_waits
- mysql\_global\_status\_innodb\_mem\_adaptive\_hash
- mysql\_global\_status\_innodb\_mem\_dictionary
- mysql\_global\_status\_innodb\_num\_open\_files
- mysql\_global\_status\_innodb\_page\_size
- mysql\_global\_status\_innodb\_pages\_written
- mysql\_global\_status\_key\_blocks\_unused
- mysql\_global\_status\_key\_blocks\_used
- mysql\_global\_status\_max\_used\_connections
- mysql\_global\_status\_open\_files
- mysql\_global\_status\_open\_table\_definitions
- mysql\_global\_status\_open\_tables
- mysql\_global\_status\_opened\_files
- mysql\_global\_status\_opened\_table\_definitions
- mysql\_global\_status\_opened\_tables
- mysql\_global\_status\_qcache\_free\_memory
- mysql\_global\_status\_qcache\_hits
- mysql\_global\_status\_qcache\_inserts
- mysql\_global\_status\_qcache\_lowmem\_prunes
- mysql\_global\_status\_qcache\_not\_cached
- mysql\_global\_status\_qcache\_queries\_in\_cache
- mysql\_global\_status\_queries
- mysql\_global\_status\_questions
- mysql\_global\_status\_select\_full\_join
- mysql\_global\_status\_select\_full\_range\_join
- mysql\_global\_status\_select\_range
- mysql\_global\_status\_select\_range\_check
- mysql\_global\_status\_select\_scan
- mysql\_global\_status\_slow\_queries
- mysql\_global\_status\_sort\_merge\_passes
- mysql\_global\_status\_sort\_range
- mysql\_global\_status\_sort\_rows
- mysql\_global\_status\_sort\_scan
- mysql\_global\_status\_table\_locks\_immediate
- mysql\_global\_status\_table\_locks\_waited
- mysql\_global\_status\_table\_open\_cache\_hits
- mysql\_global\_status\_table\_open\_cache\_misses
- mysql\_global\_status\_table\_open\_cache\_overflows
- mysql\_global\_status\_threads\_cached
- mysql\_global\_status\_threads\_connected
- mysql\_global\_status\_threads\_created
- mysql\_global\_status\_threads\_running
- mysql\_global\_status\_uptime
- mysql\_global\_status\_wsrep\_local\_recv\_queue
- mysql\_global\_status\_wsrep\_local\_state
- mysql\_global\_status\_wsrep\_ready
- mysql\_global\_variables\_innodb\_additional\_mem\_pool\_size
- mysql\_global\_variables\_innodb\_buffer\_pool\_size
- mysql\_global\_variables\_innodb\_log\_buffer\_size
- mysql\_global\_variables\_key\_buffer\_size
- mysql\_global\_variables\_max\_connections
- mysql\_global\_variables\_open\_files\_limit
- mysql\_global\_variables\_query\_cache\_size
- mysql\_global\_variables\_table\_definition\_cache
- mysql\_global\_variables\_table\_open\_cache
- mysql\_global\_variables\_thread\_cache\_size
- mysql\_global\_variables\_tokudb\_cache\_size
- mysql\_global\_variables\_wsrep\_desync
- mysql\_heartbeat\_now\_timestamp\_seconds
- mysql\_heartbeat\_stored\_timestamp\_seconds
- mysql\_info\_schema\_processlist\_threads
- mysql\_slave\_status\_seconds\_behind\_master
- mysql\_slave\_status\_slave\_io\_running
- mysql\_slave\_status\_slave\_sql\_running
- mysql\_slave\_status\_sql\_delay
- mysql\_up
- up

## Changelog

md ![Copy code to clipboard](/media/images/icons/icon-copy-small-2.svg) Copy

```md
# 1.1.5 - July 2025

* Update Kubernetes snippets to work with v2.x version of Grafana Monitoring Helm chart.

# 1.1.4 - June 2025

* Update snippets for Windows

# 1.1.3 - November 2024

* Update status panel check queries

# 1.1.2 - August 2024

* Fix asserts patches for alerts

# 1.1.1 - July 2024

* Adds asserts specific variables to dashboards

# 1.1.0 - June 2024

* Add asserts support
* Update mixin with additional alerts

# 1.0.2 - January 2024

* Allow selection of "all" clusters on MySQL overview dashboard, allowing the display of metrics which do not have the cluster tag.

# 1.0.1 - August 2023

* Add regex filter for logs datasource

# 1.0.0 - August 2023

* Add Kubernetes instructions
* Switch panels to timeseries type
* Fix stat panels to use 'last' aggegation instead of 'mean'
* Chain job and instance variables

# 0.1.1 - July 2023

* New Filter Metrics option for configuring the Grafana Agent, which saves on metrics cost by dropping any metric not used by this integration. Beware that anything custom built using metrics that are not on the snippet will stop working.
* New hostname relabel option, which applies the instance name you write on the text box to the Grafana Agent configuration snippets, making it easier and less error prone to configure this mandatory label.

# 0.1.0 - July 2023

* Updated logs dashboard
* Updated alerts annotations

# 0.0.5 - November 2022

* Add integration status panel

# 0.0.4 - April 2022

* Updated documentation and agent config snippets

# 0.0.3 - February 2022

* Added logs support from Loki datasource

# 0.0.2 - October 2021

* Update all rate queries to use `$__rate_interval`

# 0.0.1 - October 2020

* Initial release
```

## Cost

By connecting your MySQL instance to Grafana Cloud, you might incur charges. To view information on the number of active series that your Grafana Cloud account uses for metrics included in each Cloud tier, see [Active series and dpm usage](/docs/grafana-cloud/fundamentals/active-series-and-dpm/) and [Cloud tier pricing](/products/cloud/pricing/).
