How to Connect Your MySQL Instance to a Grafana Datasource

How to Connect Your MySQL Instance to a Grafana Datasource

Table of Contents

Great systems are not just built. They are monitored.

MetricFire is the fully managed Graphite and Grafana platform for small teams that don’t want to self-host their monitoring stack. Pre-built dashboards, alerts, and native add-ons for Heroku, AWS, Azure, and GCP. All with dedicated support and no infrastructure to maintain.

Introduction 

Grafana’s MySQL datasource makes it easy to turn raw database rows into clean, interactive dashboards. Whether you're testing out a new monitoring setup or experimenting with time-series data, MySQL + Grafana gives you a powerful foundation for building visualizations quickly. In this short guide, we’ll walk through:

  • Installing and configuring MySQL on Ubuntu (quick + minimal steps)

  • Creating sample CPU, Memory, and Disk metrics

  • Setting up a Grafana MySQL datasource

  • Using a query that renders all three metrics in a single panel

Don't have Grafana yet? Sign up for MetricFire's free trial to try it out and follow along with this tutorial!

Spin Up a Fresh Instance of MySQL (ubuntu)

Installation Steps

Update and install:

sudo apt update
sudo apt install mysql-server -y

Start and enable MySQL:

sudo systemctl enable --now mysql

Secure the install (recommended):

sudo mysql_secure_installation

You can safely answer YES to all prompts in a test environment.

Configuration Steps for Grafana Access (Testing Mode)

These steps intentionally use loose permissions to make Grafana connectivity easy for this demo (do not use these settings in production), and allows Grafana to connect from any IP address.

Allow MySQL to Listen Externally

Edit the config generally located at: /etc/mysql/mysql.conf.d/mysqld.cnf

Locate: bind-address = 127.0.0.1

Replace with: bind-address = 0.0.0.0


Restart MySQL

sudo systemctl restart mysql

Open Port 3306 in UFW

sudo ufw allow 3306/tcp
sudo ufw reload

Create a Grafana User With Full Access (Testing Only)

Login:

sudo mysql

Run:

CREATE DATABASE testdb;

CREATE USER 'grafana_user'@'%' IDENTIFIED BY 'your_password';
GRANT ALL PRIVILEGES ON testdb.* TO 'grafana_user'@'%';
FLUSH PRIVILEGES;

Inject Sample Data

This sample dataset makes it easy to build your first time-series graph. First, switch to your test database:

USE testdb;

Create the metrics table:

CREATE TABLE sample_data (
    id INT AUTO_INCREMENT PRIMARY KEY,
    name VARCHAR(255) NOT NULL,
    value INT NOT NULL,
    created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);


Insert data:

INSERT INTO sample_data (name, value) VALUES
  ('CPU Load', 42),
  ('Memory Usage', 8000),
('Disk Space', 380);
Now you're ready to configure a MySQL datasource in Grafana. And remember, you can test this out for FREE if you start a 14-day trial with MetricFire!

Visualize Your Sample Data in Grafana

Configure the MySQL Data Source

  1. Navigate to your Grafana instance => Connect Data => search/select MySQL
  2. Enter Details:
    • Host: <mysql_server_ip>:3306
    • Databasetestdb
    • Usergrafana_user
    • Passwordyour_password
  3. Set SSL Mode: disable
  4. Click "Save & Test"

How to Connect Your MySQL Instance to a Grafana Datasource - 1


Again, when allowing remote connections to a production DB, you should always use SSL certificates and can reference our related article HERE.

Create a Grafana Dashboard Panel

In your instance of Grafana, go to => Dashboards => New Dashboard => "Add a new panel"

Select your new MySQL Datasource, select the Code option, and enter a Query for your sample data:

SELECT
  UNIX_TIMESTAMP(created_at) AS time,
  MAX(CASE WHEN name = 'CPU Load' THEN value END) AS cpu,
  MAX(CASE WHEN name = 'Memory Usage' THEN value END) AS mem,
  MAX(CASE WHEN name = 'Disk Space' THEN value END) AS disk
FROM sample_data
GROUP BY created_at;

Then 'Run' the query to see any values you've injected into your MySQL testdb:

How to Connect Your MySQL Instance to a Grafana Datasource - 2

Conclusion

MySQL often sits at the heart of critical business applications, from internal reporting tools and customer portals to transaction systems and analytics pipelines. When the database slows down, everything built on top of it slows down with it. That’s why monitoring MySQL performance is foundational to keeping operations running smoothly. Visualizing key MySQL metrics in Grafana gives teams real-time insight into query performance, resource usage, storage trends, and potential bottlenecks before they affect end users. With clear dashboards and reliable alerting, organizations can troubleshoot issues faster, make smarter capacity decisions, and ensure their workflows remain efficient.

Sign up for the free trial and begin monitoring your infrastructure today. You can also book a demo and talk to the MetricFire team directly about your monitoring needs.

You might also like other posts...
metricfire Mar 12, 2026 · 2 min read

Telegrafを使用してDogStatsDから移行する方法

DogStatsDは便利な一方でベンダーロックインの原因にもなります。本記事ではTelegrafを使い、既存のDogStatsD計測を維持したままDatadog依存を減らし、他の監視バックエンドへ移行する方法を解説します。 Continue Reading

metricfire Mar 09, 2026 · 4 min read

NVIDIA DCGMでGPU監視|セットアップ・メトリクス・アラート設定ガイド

本記事では、DCGM Exporterのインストール方法、/metricsのスクラップ方法、Grafanaでの可視化方法、そして電力、エラー、使用率に関するアラートの設定方法を解説しています。 Continue Reading

metricfire Mar 02, 2026 · 9 min read

New Relic vs. Hosted Graphite: Two Philosophies of Observability

A balanced, developer-focused comparison of New Relic and Hosted Graphite, exploring the tradeoffs between... Continue Reading

header image

We strive for 99.95% uptime

Because our system is your system.

14-day trial 14-day trial
No Credit Card Required No Credit Card Required