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.
- Edit the /etc/mysql/mysql.conf.d/mysqld.cnf file.
- Change the bind-address from 127.0.0.1 to 0.0.0.0
- 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
- Go to configuration and data sources
- Click on “Add data source”
- Click on “MySQL”
- Name the data source
- Host should be something like “192.168.1.20:3306”
- “Database” should be the database you want to monitor.
- “User” and “Password” should be the user name and password you set up above.
- “Session timezone” should be the timezone offset like “-6:00”. Named timezones like “UTC” are not acceptable.
- Click on “Save & test”. If this fails, open a session to the Grafana server and look at /var/log/grafana/grafana.log