Heimdall 是一款专门为 MySQL 设计的命令行导入导出工具,使用它,你可以通过写 SQL 的方式,将查询结果直接导出 xlsx 、csv 、markdown 、html 、json 、yaml 、xml 、sql 等格式的文件,也可以将 xlsx 和 csv 格式的文件导入到数据库表中。
项目地址:
https://github.com/mylxsw/heimdall
heimdall 支持以下命令
使用 import/load 命令,你可以从 xlsx 或者 csv 文件导入数据库到数据表中。支持以下命令行选项:
使用 export/query 命令,你可以将 SQL 查询结果导出到各种格式的文件,当前支持 JSON/YAML/Markdown/CSV/XLSX/HTML/SQL 等格式。支持以下命令行选项::
将 xlsx 文件内容导入到数据库表 people 中,标题 区域 对应字段 area ,姓名对应 name ,身份证号对应 idcard:
heimdall import --host 127.0.0.1 --port 3306 --database example --user root --password root \
    --table people \
    --field 区域:area \ 
    --field 姓名:name \
    --field 身份证号码:idcard \
    --file ~/Downloads/data.xlsx
从业务库中导出最近 30 天新增的客户企业清单为 Excel 文件
heimdall export --database example --host 127.0.0.1 --user root --password root \
      --sql "SELECT id, name AS '企业名称', address AS '企业地址', city_name AS '城市', district_name AS '区县', DATE_FORMAT(created_at, '%Y-%m-%d %H:%i:%s') AS '创建时间' FROM enterprise WHERE created_at > DATE_SUB(NOW(), INTERVAL 30 DAY) ORDER BY id DESC" \
      --streaming \
      --format xlsx \
      --output 最近 30 天新增企业列表.xlsx
|  |      1lizhenda      2022-11-27 15:38:04 +08:00 不错哦,准备试试 | 
|  |      2v2wtf      2022-11-27 16:13:37 +08:00 nice work | 
|  |      3xiaoz      2022-11-27 16:31:25 +08:00 via Android 最近正在思考 MySQL 的备份就看到这个帖子,及时雨啊,感谢楼主。 | 
|  |      4aaa5838769      2022-11-27 16:53:11 +08:00 支持一下。 | 
|      5liaohongxing      2022-11-27 20:39:14 +08:00 非常不错 。每年都有几次 10g 左右的 mysql 数据搬迁 。不知道对于大文件导入导出内存怎么样,如果半路崩溃是怎么处理的 。能否兼容 tidb 。 | 
|  |      6xiaoz      2022-11-27 22:05:33 +08:00 @liaohongxing 老哥 10G 的数据库迁移用的什么方案? | 
|  |      7blankmiss      2022-11-27 22:10:12 +08:00 可视化的话 会不会更爽 | 
|      8ye10010      2022-11-27 22:20:39 +08:00 支持,另外问下如果有特殊字符,比如双引号,能够正确导出为 csv 之类的吗? | 
|  |      10gniviliving      2022-11-28 08:19:38 +08:00 heimdall 是一个导航页工具呀,这都能重名,世界真小 https://github.com/linuxserver/Heimdall | 
|      11fluent12138      2022-11-28 15:48:41 +08:00 不支持 SELECT * FROM `table name` 这种``的语法嘛 | 
|  |      12mylxsw OP @fluent12138 支持 | 
|  |      13defunct9      2022-11-29 13:56:09 +08:00 ./heimdall export --host 127.0.0.1 --port 3306 --database falcon --user root --password xxxxxx --format xlsx --output 1.xls panic: runtime error: index out of range [-1] goroutine 1 [running]: github.com/mylxsw/heimdall/commands.readAll({0xbe7720?, 0xc00009c000?}, 0x3b) /Users/mylxsw/Workspace/codes/github/heimdall/commands/global.go:26 +0x2c5 github.com/mylxsw/heimdall/commands.resolveExportOption(0xc0002ad648?) /Users/mylxsw/Workspace/codes/github/heimdall/commands/export.go:44 +0x85 github.com/mylxsw/heimdall/commands.ExportCommand(0xc0000d7e00?) /Users/mylxsw/Workspace/codes/github/heimdall/commands/export.go:65 +0xc5 github.com/urfave/cli/v2.(*Command).Run(0xc0000d7e00, 0xc0000a37c0, {0xc0002de2d0, 0xf, 0xf}) /Users/mylxsw/Deps/Go/pkg/mod/github.com/urfave/cli/[email protected]/command.go:271 +0xaab github.com/urfave/cli/v2.(*Command).Run(0xc0002e03c0, 0xc0000a3680, {0xc0000a4000, 0x10, 0x10}) /Users/mylxsw/Deps/Go/pkg/mod/github.com/urfave/cli/[email protected]/command.go:264 +0xd0d github.com/urfave/cli/v2.(*App).RunContext(0xc00009a1e0, {0xbeb040?, 0xc0000a60a0}, {0xc0000a4000, 0x10, 0x10}) /Users/mylxsw/Deps/Go/pkg/mod/github.com/urfave/cli/[email protected]/app.go:329 +0x665 github.com/urfave/cli/v2.(*App).Run(...) /Users/mylxsw/Deps/Go/pkg/mod/github.com/urfave/cli/[email protected]/app.go:306 main.main() /Users/mylxsw/Workspace/codes/github/heimdall/main.go:68 +0x69a | 
|  |      14defunct9      2022-11-29 13:57:21 +08:00 想给同事 show 一把的,结果没秀出来 | 
|  |      16defunct9      2022-11-30 13:30:29 +08:00 明白了,这是个表级别的工具,不是库级别的。 |