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 #12827

Merged
merged 10 commits into from
Sep 7, 2023
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 @@ The steps are as follows:
2. Configure the required labels for TiKV and PD.
3. Create the placement rule policy and apply the created policy to the target table.
4. Use TiDB Lightning to import data into the target table.

## How can I use lightning and dumpling to copy a schema
dveeden marked this conversation as resolved.
Show resolved Hide resolved

This is to copy both the schema definition and the table data from one schema to a new schema. For this example we will make a copy of the `test` schema into a new schema called `test2`.
dveeden marked this conversation as resolved.
Show resolved Hide resolved

We first create a backup with `-B test` to only select the schema that we need.

```
tiup dumpling -B test -o /tmp/bck1
```
dveeden marked this conversation as resolved.
Show resolved Hide resolved

Then we create a `/tmp/tidb-lightning.toml` file with the following content:

```
[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'
```
dveeden marked this conversation as resolved.
Show resolved Hide resolved

Here we set `schema = 'test2'` as we want to use a different schema name than the one that we had in the original dump. The name of the table is taken from the filename.
dveeden marked this conversation as resolved.
Show resolved Hide resolved

Then we use this config file to run the import.

```
tiup tidb-lightning -config /tmp/tidb-lightning.toml
```
dveeden marked this conversation as resolved.
Show resolved Hide resolved