Home Creating a MySQL Datasource in Grafana
Post
Cancel

Creating a MySQL Datasource in Grafana

These instructions tell you how to:

  • Set MySQL to allow remote connections
  • Create a dedicated MySQL user for Grafana
  • Assign read-only permissions to that user
  • Setup Grafana to monitor the MySQL server

Allow remote connections

By default, MySQL 8.x does not allow remote connections.

  1. Edit the /etc/mysql/mysql.conf.d/mysqld.cnf file.
  2. Change the bind-address from 127.0.0.1 to 0.0.0.0
  3. Restart the MySQL service (sudo systemctl restart mysql)
    Source: https://linuxize.com/post/mysql-remote-access/

Creating a dedicated Grafana MySQL user account

  • Create a dedicated Grafana user and grant it SELECT or read-only permissions.
    1
    2
    
    CREATE USER 'grafana_user_name'@'%' IDENTIFIED WITH mysql_native_password BY 'grafana_user_password';
    GRANT SELECT ON *.* TO 'grafana_user_name'@'%';
    

Test the MySQL connection

Ideally, run these commands on the Grafana server itself.

  • If you do not have the MySQL client installed, here is how you do it:
    1
    
    sudo apt install mysql-client-core-8.0
    
  • Test the connection to the MySQL server.
    1
    
    mysql -h ip_address -u grafana_user_name -p
    

Set up the MySQL data source in Grafana

  1. Go to configuration and data sources
  2. Click on “Add data source”
  3. Click on “MySQL”
  4. Name the data source
  5. Host should be something like “192.168.1.20:3306”
  6. “Database” should be the database you want to monitor.
  7. “User” and “Password” should be the user name and password you set up above.
  8. “Session timezone” should be the timezone offset like “-6:00”. Named timezones like “UTC” are not acceptable.
  9. Click on “Save & test”. If this fails, open a session to the Grafana server and look at /var/log/grafana/grafana.log
This post is licensed under CC BY 4.0 by the author.