The Prometheus ecosystem contains a multitude of integrations, both officially supported and third party. Let's have a look at how to use the mysqld_exporter.


MySQL is a popular database system, which exposes a wide variety of metrics but not in a format Prometheus can directly consume. The mysqld_exporter bridges this gap.

I'm going to assume you already have a working MySQLd installed. We first need to create a user that can connect locally with appropriate permissions:

CREATE USER 'mysqld_exporter'@'localhost' IDENTIFIED BY 'a_password';
GRANT PROCESS, REPLICATION CLIENT, SELECT ON *.* TO 'mysqld_exporter'@'localhost'

Then download and run the mysqld_exporter:

tar -xzf mysqld_exporter-0.9.0.linux-amd64.tar.gz
export DATA_SOURCE_NAME='mysqld_exporter:a_password@unix(/var/run/mysqld/mysqld.sock)/'

You may need to adjust the location of the Unix socket.

If you visit :9104/metrics you'll see your metrics!


Let's setup a Prometheus to scrape the exporter:

tar -xzf prometheus-2.0.0.linux-amd64.tar.gz
cd prometheus-*
cat <<'EOF' > prometheus.yml
 scrape_interval: 10s
 evaluation_interval: 10s
 - job_name: 'mysqld'
    - targets:
      - localhost:9104
./prometheus &

From there you can go to :9090/graph and plot expressions such as irate(mysql_global_status_queries[1m]) to get the query rate.

The mysqld_exporter can provide a wide wealth of information, however for performance reasons most of this is disabled by default. The official docs have the flags you can use to enable more metrics.


Have questions about monitoring databases with Prometheus? Contact us.