How to Connect Your MySQL Instance to a Grafana Datasource

How to Connect Your MySQL Instance to a Grafana Datasource

Table of Contents

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 Dec 17, 2025 · 4 min read

「Librato」の終了に伴い、「Hosted Graphite」へ乗り換え

アプリケーションを真剣に考えるなら、監視も真剣に取り組む必要があります。Hosted Graphiteは、現代のHerokuアプリとチームにふさわしい、深み、柔軟性、そして成長の道筋を提供します。 Continue Reading

grafana Dec 02, 2025 · 10 min read

Heroku Monitoring Best Practices (2026) | MetricFire

Level up your Heroku monitoring: key metrics, built-in tools vs add-ons, alerting tips, and... Continue Reading

metricfire Dec 02, 2025 · 13 min read

10 Best Cisco Switch Monitoring Tools (2026) | MetricFire

MetricFire provides the best hosted open-source Cisco switch network monitoring solution. It is the... 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