npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@xiaokexiang/db-cli

v0.2.3

Published

多数据库 CLI 工具 - 支持 MySQL 和达梦数据库

Readme

DB-CLI - 多数据库命令行工具

多数据库 CLI 工具,支持 MySQL 和达梦数据库的 SQL 导入、导出和执行。

安装

全局安装(推荐)

npm install -g @xiaokexiang/db-cli

安装后可使用 db-cli 命令。

快速开始

1. 连接数据库

db-cli -c '<连接字符串>' <命令> [选项]

连接字符串格式

| 数据库 | 格式 | 示例 | |--------|------|------| | 达梦数据库 | dm://用户名:密码@主机:端口 | dm://SYSDBA:SYSDBA001@localhost:5236 | | MySQL | mysql://用户名:密码@主机:端口 | mysql://root:password@localhost:3306 |

注意:连接字符串不支持数据库名,所有 schema 请通过 SQL 语句处理。

示例

# 达梦数据库
db-cli -c 'dm://SYSDBA:SYSDBA001@localhost:5236' exec -q 'SELECT 1'

# MySQL
db-cli -c 'mysql://root:password@localhost:3306' exec -q 'SELECT 1'

2. 执行 SQL 查询

# 表格输出(默认)
db-cli -c 'mysql://root:password@localhost:3306' exec -q 'SELECT * FROM users'

# JSON 输出
db-cli -c 'mysql://root:password@localhost:3306' exec -q 'SELECT * FROM users' --format json

# 多条语句执行
db-cli -c 'mysql://root:password@localhost:3306' exec -q 'SELECT 1; SELECT 2;'

# 遇到错误继续执行
db-cli -c 'mysql://root:password@localhost:3306' exec -q 'SELECT 1; INVALID_SQL; SELECT 3;' --continue-on-error

3. 导入 SQL 文件

# 导入单个 SQL 文件到 MySQL(推荐:在 SQL 文件中使用 USE 语句)
db-cli -c 'mysql://root:password@localhost:3306' import -f data.sql

# 导入单个 SQL 文件到 MySQL(使用 -s 参数指定数据库)
db-cli -c 'mysql://root:password@localhost:3306' import -s database_name -f data.sql

# 导入到达梦数据库
db-cli -c 'dm://SYSDBA:SYSDBA001@localhost:5236' import -f data.sql

# 批量导入 - 使用通配符匹配多个文件
db-cli -c 'dm://SYSDBA:SYSDBA001@localhost:5236' import -f 'boc-document/dm/sql/*.sql'

# 批量导入 - 递归匹配子目录
db-cli -c 'dm://SYSDBA:SYSDBA001@localhost:5236' import -f 'boc-document/dm/sql/**/*.sql'

# 批量导入 - 按前缀匹配
db-cli -c 'dm://SYSDBA:SYSDBA001@localhost:5236' import -f 'boc-document/dm/sql/proc-*.sql'

# 遇到错误继续执行(默认:遇到错误立即停止并回滚)
db-cli -c 'mysql://root:password@localhost:3306' import -f data.sql --continue-on-error

SQL 文件格式说明

  • MySQL: 使用 ; 作为语句分隔符,支持 #-- 注释,可以在文件开头使用 USE database_name; 选择数据库
  • 达梦数据库:支持 /; 作为语句分隔符,支持 -- 注释

批量导入说明

  • 支持通配符:*.sql 匹配单目录,**/*.sql 递归匹配子目录
  • 多个文件按顺序依次执行,每个文件内的事务独立提交
  • 如果某个文件执行失败:
    • 默认模式:立即停止,回滚当前文件的事务,后续文件不再执行
    • --continue-on-error 模式:继续执行后续文件,最终汇总显示所有错误

4. 导出数据

# 导出整个数据库(表结构 + 数据)
db-cli -c 'mysql://root:password@localhost:3306' export -s bocloud_upms

# 仅导出表结构
db-cli -c 'mysql://root:password@localhost:3306' export -s bocloud_upms --type=schema

# 仅导出数据
db-cli -c 'mysql://root:password@localhost:3306' export -s bocloud_upms --type=data

# 导出单个表
db-cli -c 'mysql://root:password@localhost:3306' export -s bocloud_upms -t upms_core_account

# 导出多个表
db-cli -c 'mysql://root:password@localhost:3306' export -s bocloud_upms -T users,roles,permissions

# 导出到文件
db-cli -c 'mysql://root:password@localhost:3306' export -s bocloud_upms -o backup.sql

# 自定义查询导出
db-cli -c 'mysql://root:password@localhost:3306' export -q 'SELECT * FROM users WHERE id > 100'

命令帮助

# 查看主帮助
db-cli --help

# 查看具体命令帮助
db-cli exec --help
db-cli import --help
db-cli export --help