Grafana Integration with MySQL Database

Nipulpatel
3 min readDec 13, 2023

--

Step 1 — Launch an AWS EC2 T2 Micro Instance. Use an existing key pair or create a new key-pair.

Step 2 — Connect to your AWS EC2 Instance and install Docker

sudo su
yum install docker -y
systemctl start docker
systemctl enable docker

Install Grafana as docker container

docker run -d — name=grafana -p 3001:3000 -v grafana_config:/etc/grafana -v grafana_data:/var/lib/grafana -v grafana_logs:/var/log/grafana grafana/grafana

After Installing the Grefana login to the grafana page

<IP Address>:3001

enter password
user_name:
admin
password:
admin

Install MySql as docker container

docker run -d — name mysqldb -p 3306:3306 -v db_data:/var/lib/mysql -e MYSQL_ROOT_PASSWORD=password mysql:latest

Execute the bellow command to run in bash

paste this command to enter in to mysql — enter password in password section

mysql -u root -p

To enter with out password

mysql -u root -p’password’

To check the MYSQL database

show databases;

Create a database ocean

create database ocean;

use ocean;

Create a table

CREATE TABLE person1 ( person_id INT NOT NULL PRIMARY KEY, fname VARCHAR(40) NULL, lname VARCHAR(40) NULL, age INT NOT NULL, created TIMESTAMP );

To check the table

Show tables;

Insert the Data in Mysql DB

Add DataSource as MYSQL in GRAFANA

First make sure that u have give proper inbound rules in aws for EC2

Go to Grafana portal → dashboard → conncetions → data source → MySQL → <IP Address>:3306 → DB name / Username (root

)and password(password) →save and test.

Select DAshboard → create new dashboard → Add visualization → select mysql.

you need to change to table view, code

To check all persons we added in the table — run the query

SELECT * FROM ocean.person

When you run the query, you will see table data like this

The data is coming from MySQL Database. So, hence we have integrated Grafana Dashboard with MySQL Database. You can write more complex queries.

--

--

No responses yet