Skip to content

Commit

Permalink
tidb-lightning-faq: Add item for copying a schema (#15512) (#15574)
Browse files Browse the repository at this point in the history
  • Loading branch information
ti-chi-bot committed Nov 30, 2023
1 parent ad88b2a commit a0af272
Showing 1 changed file with 45 additions and 0 deletions.
45 changes: 45 additions & 0 deletions tidb-lightning/tidb-lightning-faq.md
Original file line number Diff line number Diff line change
Expand Up @@ -205,3 +205,48 @@ CREATE PLACEMENT POLICY p1 PRIMARY_REGION="us-east" REGIONS="us-east,us-west";
2. 为 TiKV 和 PD 配置必要的 label。
3. 创建放置规则策略,并将策略应用到目标表上。
4. 使用 TiDB Lightning 导入数据到目标表。

## 如何使用 TiDB Lightning 和 Dumpling 复制 schema?

如果你想要将一个 schema 的定义和表数据复制到一个新的 schema 中,可以按照以下步骤进行操作。通过下面的示例,你可以了解如何将 `test` schema 复制到一个名为 `test2` 的新 schema 中。

1. 创建原 schema 的备份,使用 `-B test` 来选定需要的 schema。

```
tiup dumpling -B test -o /tmp/bck1
```

2. 创建 `/tmp/tidb-lightning.toml` 文件,内容如下:

```toml
[tidb]
host = "127.0.0.1"
port = 4000
user = "root"
[tikv-importer]
backend = "tidb"
[mydumper]
data-source-dir = "/tmp/bck1"
[[mydumper.files]]
pattern = '^[a-z]*\.(.*)\.[0-9]*\.sql$'
schema = 'test2'
table = '$1'
type = 'sql'
[[mydumper.files]]
pattern = '^[a-z]*\.(.*)\-schema\.sql$'
schema = 'test2'
table = '$1'
type = 'table-schema'
```

在上述配置文件中,如要使用一个和原始备份中不同的 schema 名称,设置 `schema = 'test2'`。文件名用于确定表的名称。

3. 使用上述配置文件运行导入。

```
tiup tidb-lightning -config /tmp/tidb-lightning.toml
```

0 comments on commit a0af272

Please sign in to comment.