---
title: "Configure MySQL exporter to generate Prometheus metrics | Grafana Cloud documentation"
description: "Configure MySQL to send metrics"
---

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

# Configure the MySQL exporter to generate Prometheus metrics

To enable the Prometheus metric for MySQL, use the [mysqld\_exporter](https://github.com/prometheus/mysqld_exporter). You can either run MySQL exporter using an environment variable or using the docker.

To configure MySQL exporter to generate Prometheus metrics, perform the following steps:

1. To run the MySQL exporter using an environment variable, run the following command.
   
   > export DATA\_SOURCE\_NAME=‘user:password@(hostname:3306)/’  
   > ./mysqld\_exporter
2. To run the MySQL exporting using Docker, run the following command.
   
   > docker network create my-mysql-network  
   > docker pull prom/mysqld-exporter
   > 
   > docker run -d  
   > -p 9104:9104  
   > --network my-mysql-network  
   > -e DATA\_SOURCE\_NAME=“user:password@(hostname:3306)/”  
   > prom/mysqld-exporter
3. To enable flags on the exporter, refer to [mysqld\_exporter](https://github.com/prometheus/mysqld_exporter).
4. To confirm that the exporter is attached to the MySQL server, ensure the following metrics are available in Prometheus.
   
   - `mysql_version_info`
   - `mysql_global_status_connections`

## Request and error metrics

Expand table

| **Metric**                                                                                                                   | **Key Performance Indicator (KPI)**                                                                                                                                                             |
|------------------------------------------------------------------------------------------------------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| Request<br /><br /><br /><br />`mysql_global_status_connections`<br /><br /><br /><br />`mysql_global_status_handlers_total` | Request Rate<br /><br /><br /><br />`rate(mysql_global_status_connections[5m])`<br /><br /><br /><br />`rate(sum without(handler) (mysql_global_status_handlers_total{handler=~“commit”})[5m])` |
| Error<br /><br /><br /><br />`mysql_global_status_connection_errors_total`                                                   | Error Ratio<br /><br /><br /><br />`rate(mysql_global_status_connection_errors_total[5m])`/ `rate(mysql_global_status_connections[5m])`                                                         |

## Resource metrics

Expand table

| **Metric**                                                                                                                                                                                  | **Key Performance Indicator (KPI)**                                                                                                                                            |
|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| Connections<br /><br /><br /><br />`mysql_global_status_max_used_connections`                                                                                                               | Connection Usage<br /><br /><br /><br />`mysql_global_status_max_used_connections` / `mysql_global_variables_max_connections`                                                  |
| Temp Tables Created<br /><br /><br /><br />`mysql_global_status_created_tmp_tables`                                                                                                         | Temp Tables Usage<br /><br /><br /><br />`avg_over_time(mysql_global_status_created_tmp_tables[5m)`                                                                            |
| Network Bytes Received<br /><br /><br /><br />`mysql_global_status_bytes_received`<br /><br /><br /><br />Network Bytes Transmitted<br /><br /><br /><br />`mysql_global_status_bytes_sent` | Data transfer rate<br /><br /><br /><br />`avg_over_time(mysql_global_status_bytes_received[5m)`<br /><br /><br /><br />`avg_over_time(mysql_global_status_bytes_received[5m)` |
| Open Files<br /><br /><br /><br />`mysql_global_status_open_files`                                                                                                                          | Open Files Usage<br /><br /><br /><br />`mysql_global_status_open_files / mysql_global_variables_open_files_limit`                                                             |

## Alerts

Expand table

| **KPI**                            | **Alert**                                                                                                         |
|------------------------------------|-------------------------------------------------------------------------------------------------------------------|
|                                    |                                                                                                                   |
| Request Rate                       | **RequestRateAnomaly**                                                                                            |
| Error Ratio                        | **ErrorRatioBreach** and **ErrorBuildup** are based on an availability SLO of `99.9`                              |
| Connection Usage, Open Files Usage | **Saturation** with severity level of `warning` and `critical` when utilization exceeds 80% and 90%, respectively |
| Temp Tables Usage                  | **ResourceRateAnomaly**                                                                                           |
| Network Bytes                      | **ResourceRateAnomaly**                                                                                           |

### Failure alerts

- MySQLDown: MySQL is not running
  
  mysql\_up != 1
- MySqlRestarted: MySQL server restarted
  
  mysql\_global\_status\_uptime &lt; 60
- MySqlSlowQueries: MySQL queries are running slow
  
  rate(mysql\_global\_status\_sloq\_queries\[1m]) * 60 &gt; 0
- MysqlSlaveSqlThreadNotRunning: MySQL slave is not running even though it is enabled
  
  mysql\_slave\_status\_master\_server\_id &gt; 0 and on (instance, asserts\_env, asserts\_site) mysql\_slave\_status\_slave\_sql\_running == 0

## Dashboards

The following MySQL dashboard shows summary level metrics.

The following dashboard shows additional metric details.

The following dashboard shows InnoDB metrics.
