← 返回
未分类

kashen-mysql DDLtoExcel

Parse MySQL 8.0 DDL scripts and export table structures to Excel format. Use when users need to convert MySQL CREATE TABLE statements into structured Excel files with field names, data types, lengths, and precision. Supports batch processing of multiple tables, with each table as a separate sheet. Ideal for database documentation, data dictionary generation, and schema analysis tasks.
Parse MySQL 8.0 DDL scripts and export table structures to Excel format. Use when users need to convert MySQL CREATE TABLE statements into structured Excel files with field names, data types, lengths, and precision. Supports batch processing of multiple tables, with each table as a separate sheet. Ideal for database documentation, data dictionary generation, and schema analysis tasks.
kashen
未分类 community v1.0.0 1 版本 100000 Key: 无需
★ 1
Stars
📥 47
下载
💾 0
安装
1
版本
#latest

概述

MySQL DDL to Excel

将 MySQL 8.0 DDL 脚本解析并导出为 Excel 格式的表结构文档。

功能

  • 解析 MySQL CREATE TABLE 语句
  • 提取字段名、数据类型、长度、精度
  • 每个表生成一个独立的 Excel Sheet
  • 支持批量处理多个表

输出格式

每个 Sheet 的格式如下:

行号内容
------------
第1行表名:表名:table_name
第2行表头:属性名数据类型长度精度
第3行+实际数据:字段信息

使用方法

方式一:使用脚本(推荐)

node scripts/parse_ddl.js <sql文件路径> [输出文件路径]

示例:

node scripts/parse_ddl.js ddl.sql 表结构导出.xlsx

方式二:在代码中使用

const { parseCreateTables, generateExcel } = require('./scripts/parse_ddl');

const fs = require('fs');
const sqlContent = fs.readFileSync('ddl.sql', 'utf-8');

// 解析表结构
const tables = parseCreateTables(sqlContent);

// 生成 Excel
generateExcel(tables, 'output.xlsx');

支持的数据类型

脚本会自动识别以下 MySQL 数据类型并设置默认长度:

数据类型默认长度
------------------
tinyint3
smallint5
mediumint7
int/integer10
bigint19
decimal/numeric38
float12
double22
datetime/timestamp6
date10
time8
year4
boolean/bool1
text/tinytext/mediumtext/longtext65535
blob/tinyblob/mediumblob/longblob65535
json1073741824
varchar(n)n
char(n)n

依赖

  • Node.js >= 14
  • xlsx 包 (npm install xlsx)

安装依赖

cd scripts
npm install xlsx

注意事项

  1. 脚本会跳过约束定义(PRIMARY KEY, INDEX, FOREIGN KEY 等)
  2. Sheet 名称限制为 31 个字符(Excel 限制)
  3. 如果表名超过 31 字符,会自动截断
  4. 如果截断后有重名,会自动添加序号后缀

示例

输入 SQL:

CREATE TABLE users (
    id bigint NOT NULL AUTO_INCREMENT,
    username varchar(50) NOT NULL,
    email varchar(100) NULL,
    created_at timestamp(6) NULL,
    PRIMARY KEY (id)
);

输出 Excel:

ABCD
---------------
1表名:users
2属性名数据类型长度精度
3idbigint190
4usernamevarchar500
5emailvarchar1000
6created_attimestamp60

版本历史

共 1 个版本

  • v1.0.0 Initial release 当前
    2026-05-27 16:05 安全 安全

安全检测

腾讯云安全 (Keen)

安全,无风险
查看报告

腾讯云安全 (Sanbu)

安全,无风险
查看报告

🔗 相关推荐

dev-programming

Mcporter

steipete
使用 mcporter CLI 直接列出、配置、认证及调用 MCP 服务器/工具(支持 HTTP 或 stdio),涵盖临时服务器、配置编辑及 CLI/类型生成功能。
★ 197 📥 68,108
dev-programming

YouTube

byungkyu
使用托管OAuth集成YouTube Data API,支持搜索视频、管理播放列表、获取频道数据及评论互动,适用于用户需要时使用此技能。
★ 142 📥 42,017
dev-programming

CodeConductor.ai

larsonreever
AI驱动平台,提供快速全栈开发、智能体、工作流自动化及低代码AI集成的可扩展产品创建。
★ 79 📥 182,807