简介
MySQL2PG 是一款用 Go 语言 开发的数据库转换工具,可将 MySQL 5.7+ 数据库无缝迁移到 PostgreSQL 10+。
核心功能
表结构、数据、视图、索引、函数、用户及权限的全链路转换
支持多种参数配置
高性能、高可靠、高移植性
核心优势对比
转换流程
┌─────────────────────────────────────────────────────────┐
│ MySQL2PG 转换流程 │
└─────────────────────────────────────────────────────────┘
│
┌───────────────────────┼───────────────────────┐
▼ ▼ ▼
[Step 0] [Step 1] [Step 2 ~ 8]
测试模式 读取表定义 执行转换
│ │ │
├─ 测试连接 ├─ 表过滤 ├─ 表结构
├─ 显示版本 │ ├─ 排除指定表 ├─ 视图
└─ 退出 │ └─ 仅同步指定表 ├─ 数据同步
│ ├─ 索引
│ ├─ 函数
│ ├─ 用户
│ ├─ 表权限
│ │
▼ ▼
[Final Step]
数据校验
│
├─ 行数对比
├─ 启用约束/索引
├─ 生成统计报告
└─ 输出不一致清单详细步骤说明
快速开始
方式一:直接下载二进制(推荐)
GitHub 已预编译好 Windows/Linux 平台的二进制文件,直接下载即可使用:
📥 下载地址:https://github.com/xfg0218/MySQL2PG/releases/tag/v2.0.0
方式二:源码编译
环境要求:Go 1.24+
# 1. 克隆仓库
git clone https://github.com/xfg0218/mysql2pg.git
cd mysql2pg
# 2. 构建项目
make build
# 3. 创建配置文件
cp config.example.yml config.yml配置文件详解
编辑 config.yml 中的 conversion 部分:
conversion:
options:
# ========== 转换开关 ==========
tableddl: true # Step 1: 转换表 DDL
data: true # Step 2: 转换数据(先 DDL 后数据)
view: true # Step 3: 转换视图
indexes: true # Step 4: 转换索引
functions: true # Step 5: 转换函数
users: true # Step 6: 转换用户
table_privileges: true # Step 7: 转换表权限
# ========== 表名/字段名处理 ==========
lowercase_columns: true # 字段名转小写(默认 true)
lowercase_tables: true # 表名转小写
# ========== 表存在时的处理 ==========
skip_existing_tables: true # 表已存在则跳过,否则创建
# ========== 指定同步范围 ==========
use_table_list: false # 是否仅同步指定表(仅 data 步骤生效)
table_list: [table1, table2] # 指定同步的表列表
exclude_use_table_list: false # 是否启用排除表列表
exclude_table_list: [table1] # 要排除的表列表
# ========== 数据同步选项 ==========
validate_data: true # 同步后验证数据一致性
truncate_before_sync: true # 同步前清空目标表数据
# ========== 性能参数 ==========
max_rows_per_batch: 10000 # 每批读取行数
batch_insert_size: 1000 # 批量插入大小
concurrency: 4 # 并发线程数
max_indexes_per_batch: 20 # 每批处理索引数问题反馈
欢迎使用!如有问题,请通过以下方式反馈:
GitHub Issues:https://github.com/xfg0218/MySQL2PG/issues
评论