MySQL Monitoring Setup: Prometheus MySQL Exporter and Grafana
In this guide, you will learn how to centrally monitor your MySQL and MariaDB servers.
You will detect performance problems early.
You will be able to track real-time metrics.
📌 Technical Summary
This guide explains the installation of MySQL and MariaDB monitoring.
The goal is to monitor bottlenecks and resource consumption.
Steps followed:
- MySQL Exporter installation
- Creating authorized users
- Prometheus integration
- Grafana panel installation
- Automation with script
🚀 What Will You Learn in This Guide?
- Install MySQL Exporter
- Secure user configuration
- Prometheus target identification
- Using Grafana dashboard
- Automatic installation scripts
🛠️ Requirements
Before you start:
- Ubuntu server (tr1-db01)
- MySQL or MariaDB service
- Prometheus and Grafana
- SSH and sudo access
✅ Method 1: Manual Installation
1️⃣ Creating a Prometheus User
This command creates an isolated system user.
sudo groupadd --system prometheus
sudo useradd -s /sbin/nologin --system -g prometheus prometheus
2️⃣ MySQL Exporter Installation
- This command downloads the latest version.
curl -s https://api.github.com/repos/prometheus/mysqld_exporter/releases/latest \
| grep browser_download_url \
| grep linux-amd64 \
| cut -d '"' -f 4 \
| wget -qi -
tar xvf mysqld_exporter*.tar.gz
sudo mv mysqld_exporter-*.linux-amd64/mysqld_exporter /usr/local/bin/
sudo chmod +x /usr/local/bin/mysqld_exporter
3️⃣ Creating a MySQL Exporter User
- This step creates the custom user for monitoring.
mysql -u root -p
CREATE USER 'mysqld_exporter'@'localhost' IDENTIFIED BY 'GucluSifre123!';
GRANT PROCESS, REPLICATION CLIENT, SELECT ON *.* TO 'mysqld_exporter'@'localhost';
FLUSH PRIVILEGES;
EXIT;
4️⃣ Credential File Creation
- This file provides secure connection.
sudo nano /etc/.mysqld_exporter.cnf
[client]
user=mysqld_exporter
password=GucluSifre123!
sudo chown root:prometheus /etc/.mysqld_exporter.cnf
5️⃣ Creating systemd Service
- This service runs Exporter continuously.
sudo nano /etc/systemd/system/mysql_exporter.service
[Unit]
Description=Prometheus MySQL Exporter
After=network.target
[Service]
User=prometheus
Group=prometheus
Restart=always
ExecStart=/usr/local/bin/mysqld_exporter \
--config.my-cnf /etc/.mysqld_exporter.cnf \
--collect.global_status \
--collect.info_schema.innodb_metrics \
--collect.auto_increment.columns \
--collect.processlist \
--collect.global_variables \
--web.listen-address=0.0.0.0:9104
[Install]
WantedBy=multi-user.target
6️⃣ Starting the Service
- This command activates the service.
sudo systemctl daemon-reload
sudo systemctl enable mysql_exporter
sudo systemctl start mysql_exporter
✅ Prometheus Configuration
Backup
- This command preserves the configuration.
cp /etc/prometheus/prometheus.yml \
/etc/prometheus/prometheus.yml.backup
MySQL Hedefi Ekleme
- This setting enables metrics collection.
sudo nano /etc/prometheus/prometheus.yml
scrape_configs:
- job_name: mysql_db01
static_configs:
- targets: ['192.168.1.60:9104']
labels:
alias: genixnode-mysql-01
Prometheus Reboot
sudo systemctl restart prometheus
✅ Method 2: Automatic Installation via Script
Target Server Script
- This script installs Exporter automatically.
wget https://solutions-files.ams3.digitaloceanspaces.com/MySQL-MariaDB-Monitoring/DO_MySQL_MariaDB_Target_Config.sh
chmod +x DO_MySQL_MariaDB_Target_Config.sh
./DO_MySQL_MariaDB_Target_Config.sh
Prometheus Script
- This script adds targets automatically.
wget https://solutions-files.ams3.digitaloceanspaces.com/MySQL-MariaDB-Monitoring/DO_MySQL_MariaDB_Prometheus_Config.sh
chmod +x DO_MySQL_MariaDB_Prometheus_Config.sh
./DO_MySQL_MariaDB_Prometheus_Config.sh
✅ Grafana Dashboard Installation
Grafana Panel
http://sunucu-ip:3000
Adding Data Source
-
Configuration > Data Sources
-
Add Data Source
-
Choose Prometheus
URL: http://localhost:9090
Dashboard Import
- Ready panel file:
wget https://solutions-files.ams3.digitaloceanspaces.com/MySQL-MariaDB-Monitoring/DO_Grafana-Mysql-MariaDB_Monitoring.json
📊 Trackable Metrics
- With this structure:
-
Query delay
-
CPU usage
-
Number of connections
-
Replication status
-
Disk I/O
is followed.
🧩 Troubleshooting
Service Check
sudo systemctl status mysql_exporter
Port Control
ss -tulnp | grep 9104
Opening Firewall
sudo ufw allow from PROMETHEUS_IP to any port 9104
❓ Frequently Asked Questions
1. Does the Exporter require root privileges? No, a special user is sufficient.
2. Are more than one database monitored? Yes, it is added to the targets list.
3. Is script or manual recommended? Manual is recommended in corporate systems.
4. Is SSL used? Yes, it is supported with reverse proxy.
5. Does it affect performance? Its impact is low.
🎯 Result With this guide: You set up MySQL monitoring You provided central monitoring You made early error detection You increased system stability
With the GenixNode infrastructure, you can install this structure immediately and monitor your databases safely. 🚀

