Heimdall 正在参加 2021 年度 OSC 中国开源项目评选,请投票支持!
Heimdall 在 2021 年度 OSC 中国开源项目评选 中已获得 {{ projectVoteCount }} 票,请投票支持!
2021 年度 OSC 中国开源项目评选 正在火热进行中,快来投票支持你喜欢的开源项目!
2021 年度 OSC 中国开源项目评选 >>> 中场回顾
Heimdall 获得 2021 年度 OSC 中国开源项目评选「最佳人气项目」 !
授权协议 MIT
开发语言 Google Go
操作系统 跨平台
软件类型 开源软件
开源组织
地区 国产
投 递 者 mylxsw
适用人群 未知
收录时间 2022-11-27

软件简介

Heimdall 是一款专门为 MySQL 设计的命令行导入导出工具,使用它,你可以通过写 SQL 的方式,将查询结果直接导出 xlsx、csv、markdown、html、json、yaml、xml、sql 等格式的文件,也可以将 xlsx 和 csv 格式的文件导入到数据库表中。

命令行选项

heimdall 支持以下命令

  • import (别名 load) 将 xlsx 或者 csv 文件导入到数据库表中
  • export (别名 query) 将 SQL 查询结果导出到各种格式的文件

import/load

使用 import/load 命令,你可以从 xlsx 或者 csv 文件导入数据库到数据表中。支持以下命令行选项:

  • --host value, -H value MySQL host (default: "127.0.0.1")
  • --port value, -P value MySQL port (default: 3306)
  • --user value, -u value MySQL user (default: "root")
  • --password value, -p value MySQL password
  • --database value, -d value MySQL database
  • --connect-timeout value database connect timeout (default: 3s)
  • --debug, -D Debug mode (default: false)
  • --file value, -i value, --input value [ --file value, -i value, --input value ] input excel or csv file path, this flag can be specified multiple times for importing multiple files at the same time
  • --table value, -t value target table name
  • --field value, -f value [ --field value, -f value ] field map, eg: excel_field:db_field, this flag can be specified multiple times
  • --include value, -I value [ --include value, -I value ] include fields, if set, only these fields will be imported, this flag can be specified multiple times
  • --exclude value, -E value [ --exclude value, -E value ] exclude fields, if set, these fields will be ignored, this flag can be specified multiple times
  • --csv-sepertor value csv file sepertor, default is ',' (default: ",")
  • --tx, -T import data using transaction, all success or all failure, only work with InnoDB or other engines that support transaction (default: false)
  • --dry-run perform import tests to verify correctness of imported files, but do not commit transactions, only work with InnoDB or other engines that support transaction (default: false)
  • --help, -h show help (default: false)

export/query

使用  export/query 命令,你可以将 SQL 查询结果导出到各种格式的文件,当前支持 JSON/YAML/Markdown/CSV/XLSX/HTML/SQL 等格式。支持以下命令行选项:

  • --host value, -H value MySQL host (default: "127.0.0.1")
  • --port value, -P value MySQL port (default: 3306)
  • --user value, -u value MySQL user (default: "root")
  • --password value, -p value MySQL password
  • --database value, -d value MySQL database
  • --connect-timeout value database connect timeout (default: 3s)
  • --debug, -D Debug mode (default: false)
  • --sql value, -s value SQL statement
  • --format value, -f value output format, support csv, json, yaml, xml, table, html, markdown, xlsx, plain, sql (default: "csv")
  • --output value, -o value write output to a file, default output directly to STDOUT
  • --streaming, -S whether to use streaming output, if using streaming output, it will not wait for the query to complete, but output line by line during the query process. The output format only supports csv/xlsx/json/plain/sql (default: false)
  • --no-header, -n do not write table header (default: false)
  • --query-timeout value, -t value query timeout, when the stream option is specified, this option is invalid (default: 2m0s)
  • --xlsx-max-row value the maximum number of rows per sheet in an Excel file, including the row where the header is located (default: 1048576)
  • --table value when the format is sql, specify the table name
  • --help, -h show help (default: false)

示例

将 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
展开阅读全文

代码

的 Gitee 指数为
超过 的项目

评论

点击加入讨论🔥(1)
暂无内容
发表了博客
{{o.pubDate | formatDate}}

{{formatAllHtml(o.title)}}

{{parseInt(o.replyCount) | bigNumberTransform}}
{{parseInt(o.viewCount) | bigNumberTransform}}
没有更多内容
暂无内容
发表了问答
{{o.pubDate | formatDate}}

{{formatAllHtml(o.title)}}

{{parseInt(o.replyCount) | bigNumberTransform}}
{{parseInt(o.viewCount) | bigNumberTransform}}
没有更多内容
暂无内容
暂无内容
1 评论
20 收藏
分享
OSCHINA
登录后可查看更多优质内容
返回顶部
顶部