The best way to Monitor MySQL Server Exercise With a Grafana Dashboard


Grafana is a well-liked open-source observability resolution that permits you to visualize metrics on graphical dashboards. Grafana has connectors for a broad choice of knowledge sources together with time collection databases, search engines like google, and particular person purposes. On this article you’ll discover ways to use Grafana to arrange easy monitoring for a MySQL database server utilizing the official Grafana Cloud integration.

Getting Began

Grafana’s obtainable for self-hosting by yourself {hardware} or as a managed SaaS platform referred to as Grafana Cloud. We’re utilizing Grafana Cloud on this tutorial as a result of it helps quickstart integrations that connect with your knowledge supply and supply pre-built dashboard layouts for the most typical metrics.

Register to your Grafana account to start. You’ll be able to create a brand new Grafana Cloud account free of charge to retailer as much as 10,000 metrics collection and 50GB of logs.

Including the MySQL Integration

You’ll be able to add the MySQL integration to your account by heading to the “Integrations and Connections” web page, accessed from the lightning bolt icon within the left sidebar. Enter “mysql” into the search bar on the high of the display screen.

image of searching for the MySQL integration in Grafana

It is best to see two outcomes seem, each labelled “MySQL”. Select the one which’s marked as an “Integration.” Integrations embrace a simplified configuration expertise and pre-built dashboard layouts for monitoring key server statistics. The choice possibility, “Information supply,” requires you to manually connect with your server, extract metrics, and assemble dashboards.

image of installing Grafana's MySQL integration

The subsequent display screen will immediate you to pick the working system and processor structure of the machine that’s internet hosting your MySQL server. Alter the dropdown menu choices to match your system. Press the blue “Set up integration” button to view the suitable Grafana Agent set up directions.

Putting in Grafana Agent

Grafana Agent is a utility that runs as a system service to gather metrics out of your machines. It sends knowledge as much as your Grafana account the place it’ll seem in your dashboards. The agent is a pared-down model of the Prometheus knowledge collector.


Operating the script proven on the MySQL integration display screen will obtain Grafana Agent, configure it along with your Grafana Cloud account, and arrange MySQL monitoring. Information shall be collected each 60 seconds if you’re utilizing the default settings.

Copy the displayed script and run it on the server that’s internet hosting your MySQL databases. You’ll see just a few strains of output because the script downloads the binary and retrieves your config file.

Test the Grafana Agent service has began efficiently earlier than you proceed:

$ sudo systemctl standing grafana-agent.service
● grafana-agent.service - Monitoring system and forwarder
     Loaded: loaded (/lib/systemd/system/grafana-agent.service; enabled; vendor preset: enabled)
     Energetic: lively (operating) since Sat 2022-08-13 17:39:03 UTC; 39s in the past

Press the “Check integration” button in your Grafana Cloud account to test all the pieces’s prepared to make use of. The agent needs to be feeding knowledge as much as Grafana.


Now you can press “View Dashboards” to begin interacting with the visualizations included with the mixing.

Exploring Your Dashboards

The MySQL integration comes with two dashboards: MySQL Overview and MySQL Logs. The Overview dashboard supplies graphs overlaying each side of your MySQL server’s operation, together with uptime, queries per second, lively connections, queries, kinds, and community exercise. You’ll be able to utilise these metrics to interrogate MySQL efficiency and establish optimization alternatives.

The Logs view affords a feed of the log recordsdata written by your MySQL server occasion. The combination routinely collects the logs inside the /var/log/mysql listing. The dashboard consists of graphs of the variety of log strains which have been written, damaged down by severity degree and error code.

The dashboards will be custom-made by clicking the settings icon within the top-right and urgent the “Make editable” button. It will allow you to change the dashboard’s configuration utilizing the opposite controls on the settings display screen. You’ll even be add so as to add and edit the graphical panels proven on the dashboard.

Grafana Agent MySQL Server Authentication

One problem you may encounter considerations the MySQL consumer account that Grafana Agent makes use of to entry your database. The agent is configured to make use of root by default. This gained’t work if MySQL root login is disabled in your server, otherwise you’ve blocked root connections to particular databases.

You’ll be able to enhance safety and regain management by making a devoted MySQL consumer for Grafana. Run the next instructions in a MySQL shell so as to add a consumer and password, then grant it privileges to entry your knowledge:

> CREATE USER 'grafana'@'localhost' IDENTIFIED BY '<your-password>';
> GRANT ALL PRIVILEGES ON *.* TO 'grafana'@'localhost';

The privilege grant on *.* permits the consumer to entry any desk in your server, throughout all schemas. You might change the GRANT assertion to limit Grafana’s privileges or restrict interactions to particular schemas and tables. Nevertheless the mixing works finest with elevated privileges that embrace the MySQL system tables. This allows assortment of essentially the most complete choice of metrics.

When you’ve created your consumer, edit your Grafana Agent configuration file to authenticate with its credentials. You’ll discover this at /and so forth/grafana-agent.yaml. Search for the next part:

    data_source_name: root@(localhost:3306)/

The data_source_name subject defines the MySQL server handle and consumer credentials. Modify it to reference your new account.

data_source_name: grafana:<your-password>@(localhost:3306)/

Restart the Grafana Agent service to use the change.

$ sudo service grafana-agent restart


Grafana’s built-in MySQL integration supplies a handy solution to monitor the efficiency of your database server. The included dashboard layouts mixture your error logs and graph all generally measured metrics, maintaining you conscious of useful resource utilization and question exercise.

Often monitoring this knowledge might help you see rising efficiency developments and resolve anomalies earlier than they develop into an issue. Manually logging and retrieving these metrics can be a chore whereas Grafana dashboards provide you with all the pieces on one display screen, facilitating environment friendly evaluation.



Please enter your comment!
Please enter your name here

Share post:



More like this

Oil Turns Decrease as Market Fails to Shake Off Put up OPEC+ Gloom

(Bloomberg) -- Oil fell — after failing to...

Flames’ Huberdeau hits new low level with third-period benching

CALGARY — Amidst a third-period comeback that gave...

Seth Meyers Cannot Consider This Trump Trial Stunt

Seth Meyers on Tuesday mocked former President Donald...