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

microgrids-mysql2pg-mcp

v1.0.7

Published

MySQL → PostgreSQL 全量数据库迁移 MCP 服务 | Powered by Bangdao Inc.

Readme

microgrids-mysql2pg-mcp

MySQL → PostgreSQL 全量数据库迁移 MCP 服务。

支持 AI 助手(Claude、Cursor 等)通过 MCP 工具调用触发数据库迁移,自动完成结构转换、数据迁移、报告生成。

Powered by Bangdao Inc.


MCP 配置(推荐:本地安装 + env)

先全局安装:

npm i -g microgrids-mysql2pg-mcp

然后在 Cursor MCP 配置中添加(连接信息通过 env 配置,工具调用时无需每次传递):

{
  "mcpServers": {
    "microgrids-mysql2pg-mcp": {
      "type": "stdio",
      "command": "microgrids-mysql2pg-mcp",
      "env": {
        "MYSQL_HOST": "10.169.17.218",
        "MYSQL_PORT": "13306",
        "MYSQL_USERNAME": "root",
        "MYSQL_PASSWORD": "your_mysql_password",
        "PG_HOST": "10.0.0.57",
        "PG_PORT": "5432",
        "PG_USERNAME": "postgres",
        "PG_PASSWORD": "your_pg_password"
      }
    }
  }
}

MCP 配置(npx 方式,无需安装)

{
  "mcpServers": {
    "microgrids-mysql2pg-mcp": {
      "type": "stdio",
      "command": "npx",
      "args": ["-y", "microgrids-mysql2pg-mcp@latest"],
      "env": {
        "MYSQL_HOST": "10.169.17.218",
        "MYSQL_PORT": "13306",
        "MYSQL_USERNAME": "root",
        "MYSQL_PASSWORD": "your_mysql_password",
        "PG_HOST": "10.0.0.57",
        "PG_PORT": "5432",
        "PG_USERNAME": "postgres",
        "PG_PASSWORD": "your_pg_password"
      }
    }
  }
}

支持的环境变量

| 环境变量 | 对应参数 | 默认值 | |---------|---------|--------| | MYSQL_HOST | mysql_host | — | | MYSQL_PORT | mysql_port | 3306 | | MYSQL_USERNAME | mysql_username | — | | MYSQL_PASSWORD | mysql_password | — | | PG_HOST | pg_host | — | | PG_PORT | pg_port | 5432 | | PG_USERNAME | pg_username | — | | PG_PASSWORD | pg_password | — | | BATCH_SIZE | batch_size | 3000 | | LARGE_TABLE_THRESHOLD | large_table_threshold | 100000 | | ENABLE_TIMESCALEDB | enable_timescaledb | false | | REPORT_OUTPUT_DIR | report_output_dir | doc | | SQL_OUTPUT_DIR | sql_output_dir | doc/sql |

优先级:工具调用参数 > 环境变量 > 代码默认值 配置了 env 后,工具调用时可只传 target_databases 等业务参数,连接信息全部省略。


工具说明

migrate_mysql_to_postgres

执行 MySQL → PostgreSQL 全量数据库迁移。

必填参数

| 参数 | 类型 | 说明 | |------|------|------| | mysql_host | string | MySQL 服务器地址 | | mysql_username | string | MySQL 用户名 | | mysql_password | string | MySQL 密码 | | pg_host | string | PostgreSQL 服务器地址 | | pg_username | string | PostgreSQL 用户名 | | pg_password | string | PostgreSQL 密码 |

可选参数

| 参数 | 类型 | 默认值 | 说明 | |------|------|--------|------| | mysql_port | number | 3306 | MySQL 端口号 | | pg_port | number | 5432 | PostgreSQL 端口号 | | batch_size | number | 3000 | 每批次写入行数 | | large_table_threshold | number | 100000 | 大表阈值(超过此行数只迁移结构) | | target_databases | string[] | [] | 指定同步的库列表,为空时同步全部非系统库 | | report_output_dir | string | "doc" | 报告文件输出目录 | | sql_output_dir | string | "doc/sql" | DDL/DML 脚本输出目录 | | enable_timescaledb | boolean | false | 是否启用 timescaledb 插件自动检测 |


迁移流程

MySQL 实例                          PostgreSQL 实例
    │                                     │
    ├─ 查询所有非系统数据库               ├─ 查询已有数据库
    └──────────── 计算差集 ───────────────┘
                       │
          ┌────────────▼────────────┐
          │     待迁移数据库列表     │
          └────────────┬────────────┘
                       │ 遍历每个数据库
                       ▼
          ┌────────────────────────────┐
          │  1. 检测 PG 扩展需求        │
          │  2. 创建 PG 数据库          │
          │  3. 安装扩展               │
          │  4. 逐表 DDL 转换 + 执行   │  → {db}_ddl.sql
          │  5. 分批迁移表数据          │  → {db}_dml.sql
          └────────────┬───────────────┘
                       ▼
          生成 migration_report_{ts}.json

输出文件

| 文件 | 说明 | |------|------| | {report_output_dir}/migration_report_{timestamp}.json | 完整迁移报告(每库每表状态) | | {report_output_dir}/table_failures_{timestamp}.json | 实时写入的失败记录 | | {sql_output_dir}/{database}_ddl.sql | 建表、索引、注释语句 | | {sql_output_dir}/{database}_dml.sql | 已成功迁移表的 INSERT 语句 |


类型映射

| MySQL | PostgreSQL | |-------|-----------| | tinyint(1) | BOOLEAN | | tinyint | SMALLINT | | smallint | INTEGER | | mediumint / bigint | BIGINT | | int / integer | INTEGER | | float / double | NUMERIC | | decimal(p,s) | DECIMAL(p,s) | | varchar(n) | VARCHAR(n) | | char(n) | CHAR(n) | | *text / *blob | TEXT | | datetime / timestamp | TIMESTAMP | | date | DATE | | time | TIME | | year | VARCHAR(4) | | json | JSONB | | enum / set | TEXT | | bit(1) | SMALLINT (int2) | | bit(n) (n>1) | BIT(n) | | AUTO_INCREMENT (int) | SERIAL | | AUTO_INCREMENT (bigint) | BIGSERIAL |


本地开发

# 安装依赖
npm install

# 编译
npm run build

# 本地运行
npm start

发布到 NPM

# 登录 NPM
npm login

# 构建并发布
npm publish

发布后其他人可通过以下方式使用:

npx -y microgrids-mysql2pg-mcp@latest

环境要求

  • Node.js >= 18.0.0
  • npm >= 8.0.0