惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

J
Java Code Geeks
GbyAI
GbyAI
Google DeepMind News
Google DeepMind News
Jina AI
Jina AI
B
Blog
aimingoo的专栏
aimingoo的专栏
酷 壳 – CoolShell
酷 壳 – CoolShell
T
The Blog of Author Tim Ferriss
Last Week in AI
Last Week in AI
月光博客
月光博客
H
Help Net Security
V
Visual Studio Blog
量子位
A
About on SuperTechFans
博客园 - Franky
人人都是产品经理
人人都是产品经理
N
Netflix TechBlog - Medium
云风的 BLOG
云风的 BLOG
雷峰网
雷峰网
Martin Fowler
Martin Fowler
Microsoft Security Blog
Microsoft Security Blog
博客园 - 叶小钗
P
Proofpoint News Feed
MongoDB | Blog
MongoDB | Blog

Jiajun的技术笔记

你好,2026! TiDB 源码阅读(六):TiDB Coprocessor 源码解析 性能优化的核心思想 TiDB 源码阅读(五):索引 TiDB 源码阅读(四):AST、逻辑计划、物理计划 CockroachDB Serverless Architecture podman 无故退出 Cursor Control-L (CTRL-L) Keyboard Shortcuts in Terminal Replace docker with podman Using xmonad with xfce4 A RC script for freebsd frpc 自己动手写一个k8s controller AI 会取代你的(编程)岗位吗? 自建DERP服务器提升Tailscale连接速度(使用Nginx转发) 自动升级Docker容器 再读《程序员修炼之道-从小工到专家》 让浏览器下载文件 再读《软件随想录》/《黑客与画家》/《软技能》 HTTP 压力测试中的 Coordinated Omission 2的补码 编程语言中的 context 是什么? flutter macOS 构建出错 Flatpak 使用小记 Golang CAS 操作是怎么实现的 PostgreSQL 当MQ来使用 Clash 结合 工作VPN 的网络设计 使用 PostgreSQL 搭建 JuiceFS PostgreSQL 配置优化和日志分析 有GitHub Copilot?那就可以搭建你的ChatGPT4服务 窗口函数的使用(以PG为例)
将SQLite的数据迁移到MySQL
Jiajun Huang · 2019-10-15 · via Jiajun的技术笔记

这几天将Grafana的数据库 /var/lib/grafana/grafana.db 迁移到了 MySQL,原因是不想维护多个数据库备份,全都丢MySQL里,统一 管理,统一备份即可。

首先将 grafana 服务暂停一下,省得写新数据进去:

$ sudo systemctl stop grafana

然后执行命令把SQLite的数据导出来:

#!/bin/bash
DB=$1
TABLES=$(sqlite3 $DB .tables | sed -r 's/(\S+)\s+(\S)/\1\n\2/g' | grep -v migration_log)
for t in $TABLES; do
    echo "TRUNCATE TABLE $t;"
done
for t in $TABLES; do
    echo -e ".mode insert $t\nselect * from $t;"
done | sqlite3 $DB
$ ./export_sqlite.sh grafana.db > grafana.sql

接着改 grafana 的配置文件 /etc/grafana.ini 把MySQL中创建好的数据库、用户名、密码写进去:

如果没有创建好,那么应当先创建一个。

[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.

type = mysql
host = 127.0.0.1:3306
name = grafana
user = grafanauser
password = grafana123
url = mysql://grafanauser:[email protected]:3306/grafana

接着启动一下grafana,让它在MySQL中创建好表: sudo systemctl start grafana,使用 journalctl -u grafana.service -f 看着日志,当日志显示数据库migration已经做完了之后,就可以再次停用grafana,然后把数据导进去:

$ mysql -u grafanauser -p -D grafana < grafana.sql

最后,启动grafana,大功告成!


参考资料: