8.02 Migrating to MySQL - MartinWong06/grafana GitHub Wiki
1. Update OS apt repo
sudo apt update
2. Install MySQL server
sudo apt install mysql-server
3. Check MySQL server status
sudo service mysql status
4. Login to the MySQL server
sudo mysql
5. Create database for grafana
create database grafana;
6. Create db user
CREATE USER 'grafana'@'localhost' IDENTIFIED BY 'grafana';
7. Grant privilege to grafana user
grant all privileges on grafana.* to 'grafana'@'localhost';
8. Apply the changes to the DB server
flush privileges;
9. Quit MySQL
quit
10. Install sqlite3 - use for dumb the data from existing Grafana server
sudo apt install sqlite3
11. Clone the migrator tool into the specific path
cd /opt/
sudo git clone https://github.com/grafana/database-migrator.git
12. Enter migrator path
cd database-migrator/
13. Grant execute right to shell script
sudo chmod +x sqlitedump.sh
14. We must stop grafana-server
sudo systemctl stop grafana-server
sudo systemctl status grafana-server
15. Dump the sqlite3 data to db_dump.sql
sudo touch /opt/db_dump.sql
sudo chmod 777 /opt/db_dump.sql
sudo ./sqlitedump.sh /var/lib/grafana/grafana.db > /opt/db_dump.sql
16. Configure grafanan.ini according your settings
sudo nano /etc/grafana/grafana.ini
#################################### Database ####################################
[database]
# You can configure the database connection by specifying type, host, name, user and password
# as separate properties or as on string using the url properties.
# Either "mysql", "postgres" or "sqlite3", it's your choice
type = mysql
host = 127.0.0.1:3306
name = grafana
user = grafana
# If the password contains # or ; you have to wrap it with triple quotes. Ex """#password;"""
password = grafana
17. Start Grafana server, to allow grafana create the necessary table in MySQL
sudo systemctl start grafana-server
sudo systemctl status grafana-server
18. After completed table creation, stop the Grafana server.
sudo systemctl stop grafana-server
19. Migrate the sqlite3 data into MySQL server
sudo mysql -u grafana -p grafana < /opt/db_dump.sq
20. After completed migration, start the Grafana server.
sudo systemctl start grafana-server
***[mysqld]/etc/mysql/mysql.conf.d/mysqld.cnf bind-address = 0.0.0.0