8.02 Migrating to MySQL - MartinWong06/grafana GitHub Wiki

1. Update OS apt repo
sudo apt update2. Install MySQL server
sudo apt install mysql-server3. Check MySQL server status
sudo service mysql status4. Login to the MySQL server
sudo mysql5. 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
quit10. Install sqlite3 - use for dumb the data from existing Grafana server
sudo apt install sqlite311. Clone the migrator tool into the specific path
cd /opt/
sudo git clone https://github.com/grafana/database-migrator.git12. Enter migrator path
cd database-migrator/13. Grant execute right to shell script
sudo chmod +x sqlitedump.sh14. We must stop grafana-server
sudo systemctl stop grafana-serversudo systemctl status grafana-server15. Dump the sqlite3 data to db_dump.sql
sudo touch /opt/db_dump.sqlsudo chmod 777 /opt/db_dump.sqlsudo ./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 = grafana17. Start Grafana server, to allow grafana create the necessary table in MySQL
sudo systemctl start grafana-serversudo systemctl status grafana-server18. After completed table creation, stop the Grafana server.
sudo systemctl stop grafana-server19. Migrate the sqlite3 data into MySQL server
sudo mysql -u grafana -p grafana < /opt/db_dump.sq20. 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