Files
aiData/DataX/scheme/README.md
HuangHai 8e0309bb7b 'commit'
2026-02-05 13:24:59 +08:00

43 lines
1.5 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# 表结构生成工具
该工具用于连接 MySQL 数据库,自动获取表结构元数据,并生成适用于 MySQL 和 Doris 的 `CREATE TABLE` 语句。
## 功能特点
1. **元数据提取**:从 `information_schema` 获取字段名、类型、长度、是否为空、默认值及注释。
2. **MySQL DDL 生成**:生成标准的 MySQL 建表语句。
3. **Doris DDL 生成**:
- 自动映射 MySQL 类型到 Doris 类型(如 `text` -> `string`)。
- 使用 **Unique Key** 模型(支持幂等写入/覆盖更新)。
- 默认配置为单副本(`replication_num = 1`),适用于单机部署。
- 默认设置 1 个分桶(`BUCKETS 1`)。
## 使用方法
### 1. 配置数据库
编辑 `generate_schema.py` 文件开头的 `DB_CONFIG` 变量:
```python
DB_CONFIG = {
"host": "your_host",
"port": 3306,
"user": "your_user",
"password": "your_password",
"database": "your_db",
"charset": "utf8mb4"
}
```
### 2. 运行脚本
- **自动处理**:如果不传参数,脚本将自动读取 `../json/` 目录下的所有 `.json` 文件名作为表名进行批量处理。
```bash
python generate_schema.py
```
- **指定表名**:也可以手动传入需要生成结构的表名(支持多个):
```bash
python generate_schema.py 表名1 [表名2] ...
```
### 3. 查看输出
生成的 SQL 文件将存放在 `output/` 目录下:
- `表名_mysql.sql`: MySQL 建表语句
- `表名_doris.sql`: Doris 建表语句