# Migrate sqlite to mysql

**URL:** <https://community.grafana.com/t/migrate-sqlite-to-mysql/46590>\
**Category:** Configuration\
**Tags:** mysql\
**Created:** [April 25, 2021, 7:37am UTC](https://community.grafana.com/t/migrate-sqlite-to-mysql/46590 "2021-04-25T07:37:50Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![nesabian](https://sea2.discourse-cdn.com/grafana/user_avatar/community.grafana.com/nesabian/32/16133_2.png) [@nesabian](https://community.grafana.com/u/nesabian)\
**Post date:** [April 25, 2021, 7:37am UTC](https://community.grafana.com/t/migrate-sqlite-to-mysql/46590/1 "2021-04-25T07:37:50Z")

</div>

Hi  
we have a grafana that is using SQLite as the backend and now it is getting very big so we want to migrate the data to MySQL, is there any safe way to perform this?

---

<div class="post-metadata">

**Author:** ![anon70503803](https://avatars.discourse-cdn.com/v4/letter/a/8797f3/32.png) [@anon70503803](https://community.grafana.com/u/anon70503803)\
**Post date:** [April 26, 2021, 11:15pm UTC](https://community.grafana.com/t/migrate-sqlite-to-mysql/46590/2 "2021-04-26T23:15:21Z")

</div>

Hi @nesabian,

The Grafana team maintains a handy script for migrating grafana configuration data from SQLite to MySQL.

check this out:

> **[GitHub - grafana/database-migrator: Code to export grafana.db (sqlite) to...](https://github.com/grafana/database-migrator)**
>
> Code to export grafana.db (sqlite) to MySQL-compatible SQL file, to assist in migration of Grafana data to MySQL-compatible DB. - GitHub - grafana/database-migrator: Code to export grafana.db (sqli...

You might also like this long thread on the same topic:

> [@Migrating grafana data to new database](https://community.grafana.com/t/migrating-grafana-data-to-new-database/2454):
>
> We’re moving our Grafana instances to new HA servers, so we need to move the data from sqlite to a MySQL/MariaDB (Galera) cluster. I’m curious if anyone has developed any handy tools for doing such a migration? Using the API and tools like wizzy is clean, but won’t move user data, so I think some sort of direct SQL migration is required. However, I’m thinking it’s best to let Grafana create the schema in MySQL, rather than trying to translate the schema from a database dump. Maybe it won’t be t…

---

<div class="post-metadata">

**Author:** ![sowmyabm](https://avatars.discourse-cdn.com/v4/letter/s/47e85d/32.png) [@sowmyabm](https://community.grafana.com/u/sowmyabm)\
**Post date:** [June 18, 2024, 1:37pm UTC](https://community.grafana.com/t/migrate-sqlite-to-mysql/46590/3 "2024-06-18T13:37:18Z")

</div>

Hi,

I’m currently working on setting up highly available Grafana servers for our organization. As part of this process, we are transitioning the Grafana database to MySQL, hosted externally. However, I’m encountering an issue when attempting to migrate the data using the Grafana data migrator script available online.

Specifically, I’m seeing the following error when running `sqlitedump.sh`:

```auto

> awk: escape.awk: line 4: syntax error at or near ,

```

I am following the exact steps provided by this [GitHub repository](https://github.com/grafana/database-migrator). Despite reviewing various documents and resources, all point back to this repository, but none address the error I am facing.

Could someone please assist me in resolving this issue or suggest an alternative approach for migrating the Grafana data to MySQL? Your guidance would be greatly appreciated.

Thank you.

 ![WhatsApp Image 2024-06-18 at 19.00.52](https://us1.discourse-cdn.com/grafana/original/3X/c/c/cc2aa8134aafadc4b1629af6fcc28d4bb89613de.jpeg)[https://github.com/grafana/database-migrator](https://github.com/grafana/database-migrator)

---

<div class="post-metadata">

**Author:** ![yosiasz](https://sea2.discourse-cdn.com/grafana/user_avatar/community.grafana.com/yosiasz/32/45847_2.png) [@yosiasz](https://community.grafana.com/u/yosiasz)\
**Post date:** [June 18, 2024, 1:44pm UTC](https://community.grafana.com/t/migrate-sqlite-to-mysql/46590/4 "2024-06-18T13:44:05Z")

</div>

open escape.awk and look at line 4

---

<div class="post-metadata">

**Author:** ![sowmyabm](https://avatars.discourse-cdn.com/v4/letter/s/47e85d/32.png) [@sowmyabm](https://community.grafana.com/u/sowmyabm)\
**Post date:** [June 18, 2024, 1:45pm UTC](https://community.grafana.com/t/migrate-sqlite-to-mysql/46590/5 "2024-06-18T13:45:30Z")

</div>

Hi, yes I did that. Not sure what is wrong with this script

# this script is used to backtick tables and columns for each insert statement

/^INSERT/ {  
# Match columns definition  
match($0, /^INSERT INTO (.+)(([^)]+)) VALUES((.+));$/, matches)

```
table = matches[1]
middle = matches[2]
values = matches[3]

# strip all quotes from columns and create an array of column
# names
gsub(/"/, "", middle)
split(middle, columns, ",")

sep = ""
cols = ""
for(i in columns) {
    cols = cols sep "`" columns[i] "`"
    sep = ","
}

printf("INSERT INTO `%s` (%s) VALUES (%s);\n", table, cols, values)

```

}

---

<div class="post-metadata">

**Author:** ![yosiasz](https://sea2.discourse-cdn.com/grafana/user_avatar/community.grafana.com/yosiasz/32/45847_2.png) [@yosiasz](https://community.grafana.com/u/yosiasz)\
**Post date:** [June 18, 2024, 9:11pm UTC](https://community.grafana.com/t/migrate-sqlite-to-mysql/46590/6 "2024-06-18T21:11:57Z")

</div>

which one is line 4?

---

<div class="post-metadata">

**Author:** ![hiteshhari123](https://avatars.discourse-cdn.com/v4/letter/h/d6d6ee/32.png) [@hiteshhari123](https://community.grafana.com/u/hiteshhari123)\
**Post date:** [January 9, 2025, 4:40am UTC](https://community.grafana.com/t/migrate-sqlite-to-mysql/46590/7 "2025-01-09T04:40:00Z")

</div>

Hi ,

When I bring up grafana services post connecting to mysql I can see that not all tables are getting created which were there in sqllite3, due to which I cannot migrate the data any suggestions please?

---

<div class="post-metadata">

**Author:** ![rvandenzel](https://avatars.discourse-cdn.com/v4/letter/r/8dc957/32.png) [@rvandenzel](https://community.grafana.com/u/rvandenzel)\
**Post date:** [May 7, 2026, 1:21pm UTC](https://community.grafana.com/t/migrate-sqlite-to-mysql/46590/8 "2026-05-07T13:21:46Z")

</div>

I have used the procedure grom GitHub, but when I start grafana-server my MySQL DB stays empty.

From grafana.ini

;type = mysql  
;host = 127.0.0.1:3306  
;name = grafana  
;user = grafana  
;password =

I’ve checked an can login to mysql with the grafana user.

---

<div class="post-metadata">

**Author:** ![rvandenzel](https://avatars.discourse-cdn.com/v4/letter/r/8dc957/32.png) [@rvandenzel](https://community.grafana.com/u/rvandenzel)\
**Post date:** [May 7, 2026, 1:32pm UTC](https://community.grafana.com/t/migrate-sqlite-to-mysql/46590/9 "2026-05-07T13:32:38Z")

</div>

Never mind, I just forgot to remove the ‘;’
