Support Online
Skip to main content

MySQL and MariaDB Performance Tracking with Prometheus MySQL Monitoring

MySQL and MariaDB Performance Tracking with Prometheus MySQL Monitoring

In this guide, you will learn how to monitor your MySQL and MariaDB databases using Prometheus MySQL Exporter. We will detail the step-by-step installation, security settings and visualization processes with Grafana. In this way, you will be able to instantly monitor the performance of your databases and detect possible bottlenecks early.

What Will You Learn in This Guide?

  • Installing MySQL Exporter manually or automatically.
  • Visualizing database metrics with Prometheus and Grafana integration.
  • Ways to monitor and optimize MySQL and MariaDB database performance.

1. Step: Creating a System User

In order to run the Prometheus MySQL Exporter service securely, we must create a limited privileged user named prometheus.

sudo groupadd --system prometheus
sudo useradd -s /sbin/nologin --system -g prometheus prometheus
  • These commands create an isolated prometheus user and group for the service.

2. Step: MySQL Exporter Installation

  • We download MySQL Exporter from GitHub and move it to the system directory.

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
  • These commands download the MySQL Exporter file, unarchive it and make it executable.

3. Step: Database Authorization

  • Exporter needs a limited authorized user to read database metrics.

CREATE USER 'mysqld_exporter'@'localhost' IDENTIFIED BY 'guclu_sifre';
GRANT PROCESS, REPLICATION CLIENT, SELECT ON *.* TO 'mysqld_exporter'@'localhost';
FLUSH PRIVILEGES;
  • With these commands, we define the mysqld_exporter user and grant the necessary privileges.

  • Then save this information in /etc/.mysqld_exporter.cnf:

[client]
user=mysqld_exporter
password=guclu_sifre
  • We save the information of the mysqld_exporter user in the configuration file.

4. Step: Starting the Service

  • We create a systemd service for Exporter to run continuously in the background.

sudo systemctl daemon-reload
sudo systemctl enable mysql_exporter
sudo systemctl start mysql_exporter
  • These commands start the MySQL Exporter service and make it run automatically when the system restarts.

5. Step: Prometheus and Grafana Configuration

  • Go to your Prometheus server and add the IP address of your database server to the prometheus.yml file.

scrape_configs:
- job_name: server1_db
static_configs:
- targets: ['SUNUCU_IP:9104']
labels:
alias: db1
  • In Grafana, select Prometheus as the data source and import ready-made panels for visualization.

Frequently Asked Questions (FAQ)

1. What port does MySQL Exporter use? By default it uses port 9104. You must allow this port on your firewall.

2. Can I monitor more than one server at the same time? Yes, just install Exporter on each server and add it as a new "target" to the Prometheus configuration.

3. Will I lose performance? No, MySQL Exporter consumes very low resources and does not affect database performance.

Result

Monitor your MySQL and MariaDB servers with Prometheus MySQL Exporter. Step-by-step installation, security settings and Grafana visualization guide.

You can now try high-speed cloud servers on the GenixNode platform to maximize the performance of your database servers.

Next Step: If you have your database metrics ready, would you like to take a look at setting up Node Exporter to monitor server resources?