Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tidb-lightning-faq: Add item for copying a schema #15512

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 45 additions & 0 deletions tidb-lightning/tidb-lightning-faq.md
Original file line number Diff line number Diff line change
Expand Up @@ -175,3 +175,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
```