You can support us by downloading this article as PDF from the Link below. Download the guide as PDF

Prometheus MySQL Exporter is a client application used to get MySQL metrics and export to Prometheus server. The installation and usage of Prometheus MySQL Exporter to monitor MySQL/MariaDB servers were covered in Monitoring MySQL / MariaDB with Prometheus in five minutes.

In this article, I’ll summarise the guide for guys whose interest is just to install Prometheus MySQL exporter.

Step 1: Add Prometheus system user and group:

Create dedicated Prometheus user and group.

sudo groupadd --system prometheus
sudo useradd -s /sbin/nologin --system -g prometheus prometheus

This user will manage the exporter service.

Step 2: Download and install Prometheus MySQL Exporter:

This should be done on MySQL / MariaDB servers, both slaves and master servers. You may need to check Prometheus MySQL exporter releases page for the latest release, then export the latest version  to VER variable as shown below:

curl -s   | grep browser_download_url | grep linux-amd64 |  cut -d '"' -f 4 | wget -qi -

Extract the file after downloading:

tar xvf mysqld_exporter-*.linux-amd64.tar.gz

Give extracted file executable bits and move it to /usr/local/bin directory.

cd mysqld_exporter-*.linux-amd64/

Clean installation by removing the tarball and extraction directory:

chmod +x mysqld_exporter
sudo mv mysqld_exporter /usr/local/bin

Check the version of the software installed.

$ mysqld_exporter --version
mysqld_exporter, version 0.12.1 (branch: HEAD, revision: 48667bf7c3b438b5e93b259f3d17b70a7c9aff96)
  build user:       [email protected]
  build date:       20190729-12:35:58
  go version:       go1.12.7

Step 3: Create Prometheus exporter database user

The user should have PROCESS, SELECT, REPLICATION CLIENT grants

CREATE USER 'mysqld_exporter'@'localhost' IDENTIFIED BY 'StrongPassword' WITH MAX_USER_CONNECTIONS 2;
GRANT PROCESS, REPLICATION CLIENT, SELECT ON *.* TO 'mysqld_exporter'@'localhost';

If you have a Master-Slave database architecture, create user on the master servers only.

WITH MAX_USER_CONNECTIONS 2 is used to set a max connection limit for the user to avoid overloading the server with monitoring scrapes under heavy load.

Step 4: Configure database credentials

Create database credentials file

sudo vim /etc/.mysqld_exporter.cnf

Add correct username and password for user create


Set ownership permissions:

sudo chown root:prometheus /etc/.mysqld_exporter.cnf

Step 5: Create systemd unit file ( For Systemd systems )

This is for systemd servers, for SysV init system, use Prometheus MySQL exporter init script for SysV init system

Create a new service file:

sudo vim /etc/systemd/system/mysql_exporter.service

Add the following content

Description=Prometheus MySQL Exporter

ExecStart=/usr/local/bin/mysqld_exporter \ <strong>/etc/.mysqld_exporter.cnf</strong> \
--collect.global_status \
--collect.info_schema.innodb_metrics \
--collect.auto_increment.columns \
--collect.info_schema.processlist \
--collect.binlog_size \
--collect.info_schema.tablestats \
--collect.global_variables \
--collect.info_schema.query_response_time \
--collect.info_schema.userstats \
--collect.info_schema.tables \
--collect.perf_schema.tablelocks \
--collect.perf_schema.file_events \
--collect.perf_schema.eventswaits \
--collect.perf_schema.indexiowaits \
--collect.perf_schema.tableiowaits \
--collect.slave_status \


If your server has a public and private network, you may need to replace with private IP, e.g.

When done, reload systemd and start mysql_exporter service.

sudo systemctl daemon-reload
sudo systemctl enable mysql_exporter
sudo systemctl start mysql_exporter

If your system doesn’t support systemd init, use

Prometheus MySQL exporter init script for SysV init system

If you’re interested in knowing how to add targets to Prometheus server and start visualizing metrics with Grafana, then you need to check our guide how to:

Monitoring MySQL / MariaDB with Prometheus in five minutes

How To Monitor Etcd Cluster with Prometheus and Grafana

How To Monitor BIND DNS server with Prometheus and Grafana

You can support us by downloading this article as PDF from the Link below. Download the guide as PDF


Please enter your comment!
Please enter your name here