How to Monitor MySQL with Prometheus and Grafana
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 for common MySQL performance indicators, providing a complete end‑to‑end monitoring solution.
Prometheus is a popular open‑source monitoring system, and monitoring MySQL is one of its key use cases. This article walks through the process of setting up MySQL monitoring using Prometheus, MySQL Exporter, and Grafana.
1. Install MySQL Exporter
Download and extract the exporter package, then create a configuration file with the MySQL credentials (use a read‑only account in production).
$ 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 $ mkdir -p /etc/mysql_exporter/
$ vi /etc/mysql_exporter/my.cnf
[client]
user=root
password=123456Start 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. Set Up Grafana Dashboard
Import a MySQL dashboard (e.g., ID 7362) in Grafana via Create → Import , select the Prometheus data source, and apply the dashboard to visualize the collected metrics.
4. Configure Alerts
Define alerting rules for important MySQL metrics such as mysql_global_status_threads_connected , mysql_global_status_threads_running , mysql_global_status_queries , mysql_global_status_slow_queries , mysql_global_status_aborted_clients , mysql_global_status_aborted_connects , and mysql_global_variables_max_connections . These alerts help DBA teams detect issues early.
By following these steps, you obtain a complete monitoring and alerting solution for MySQL using Prometheus and Grafana.
DevOps Operations Practice
We share professional insights on cloud-native, DevOps & operations, Kubernetes, observability & monitoring, and Linux systems.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.