Operations 5 min read

Monitoring MySQL with Prometheus and Grafana: Installation, Configuration, and Alerting Guide

This tutorial explains how to install the MySQL Exporter, configure Prometheus to scrape MySQL metrics, set up Grafana dashboards for visualization, and define alerting rules, providing a complete end‑to‑end solution for monitoring MySQL databases in production environments.

DevOps Operations Practice
DevOps Operations Practice
DevOps Operations Practice
Monitoring MySQL with Prometheus and Grafana: Installation, Configuration, and Alerting Guide

Prometheus is a popular open‑source monitoring system, and monitoring MySQL is a key use case because MySQL is the most widely used relational database. Proper MySQL monitoring is essential for ensuring business stability.

In this article we describe how to monitor MySQL using Prometheus.

1. Install MySQL Exporter

The MySQL Exporter collects metrics such as connections, queries, and errors. It is typically installed on the MySQL server.

Steps:

$ wget https://github.com/prometheus/mysqld_exporter/releases/download/v0.13.0/mysqld_exporter-0.13.0.linux-amd64.tar.gz
$ tar -zxvf mysqld_exporter-0.13.0.linux-amd64.tar.gz

Create a configuration file with the MySQL credentials (use a read‑only account in production):

$ mkdir -p /etc/mysql_exporter/
$ vi /etc/mysql_exporter/my.cnf
[client]
user=root
password=123456

Start the exporter:

$ cd mysqld_exporter-0.13.0.linux-amd64
$ ./mysqld_exporter --config.my-cnf=/etc/mysql_exporter/my.cnf &

2. Configure Prometheus

Add a job to prometheus.yml to scrape the exporter every 5 seconds:

- job_name: 'mysql'
  scrape_interval: 5s
  static_configs:
    - targets: ['192.168.214.112:9104']

Restart Prometheus:

$ prometheus --config.file /etc/prometheus/prometheus.yml &

Verify that the target is up and that metrics are being collected.

3. Configure Grafana Dashboard

After Prometheus is gathering data, import a MySQL dashboard template (e.g., ID 7362) in Grafana:

Click “Create → Import”.

Enter the dashboard ID and load it.

Provide a name and select the Prometheus data source.

The imported dashboard visualizes MySQL metrics.

4. Set Up Alerting

Define alert thresholds for important MySQL metrics (e.g., threads_connected, threads_running, queries, slow_queries, aborted_clients, aborted_connects, max_connections). Use Prometheus alerting rules or refer to the linked article for detailed configuration.

Common metrics to monitor:

mysql_global_status_threads_connected – current client connections.

mysql_global_status_threads_running – running threads.

mysql_global_status_queries – total queries.

mysql_global_status_slow_queries – slow queries.

mysql_global_status_aborted_clients – aborted client connections.

mysql_global_status_aborted_connects – failed connection attempts.

mysql_global_variables_max_connections – max allowed connections.

With Prometheus, Grafana, and appropriate alert rules, MySQL monitoring is complete.

monitoringalertingPrometheusMySQLGrafanaExporter
DevOps Operations Practice
Written by

DevOps Operations Practice

We share professional insights on cloud-native, DevOps & operations, Kubernetes, observability & monitoring, and Linux systems.

0 followers
Reader feedback

How this landed with the community

login Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.