Skip to content

Commit e937391

Browse files
authored
tidb-lightning-faq: Add item for copying a schema (#12827) (#14751)
1 parent 2663324 commit e937391

File tree

1 file changed

+45
-0
lines changed

1 file changed

+45
-0
lines changed

tidb-lightning/tidb-lightning-faq.md

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,3 +204,48 @@ The steps are as follows:
204204
2. Configure the required labels for TiKV and PD.
205205
3. Create the placement rule policy and apply the created policy to the target table.
206206
4. Use TiDB Lightning to import data into the target table.
207+
208+
## How can I use TiDB Lightning and Dumpling to copy a schema?
209+
210+
If you want to copy both the schema definition and table data from one schema to a new schema, follow the steps in this section. In this example, you'll learn how to make a copy of the `test` schema into a new schema called `test2`.
211+
212+
1. Create a backup of the original schema with `-B test` to select only the schema that you need.
213+
214+
```
215+
tiup dumpling -B test -o /tmp/bck1
216+
```
217+
218+
2. Create a `/tmp/tidb-lightning.toml` file with the following content:
219+
220+
```toml
221+
[tidb]
222+
host = "127.0.0.1"
223+
port = 4000
224+
user = "root"
225+
226+
[tikv-importer]
227+
backend = "tidb"
228+
229+
[mydumper]
230+
data-source-dir = "/tmp/bck1"
231+
232+
[[mydumper.files]]
233+
pattern = '^[a-z]*\.(.*)\.[0-9]*\.sql$'
234+
schema = 'test2'
235+
table = '$1'
236+
type = 'sql'
237+
238+
[[mydumper.files]]
239+
pattern = '^[a-z]*\.(.*)\-schema\.sql$'
240+
schema = 'test2'
241+
table = '$1'
242+
type = 'table-schema'
243+
```
244+
245+
In this configuration file, set `schema = 'test2'` as you want to use a different schema name than the one used in the original dump. The filename is used to determine the name of the table.
246+
247+
3. Use this configuration file to run the import.
248+
249+
```
250+
tiup tidb-lightning -config /tmp/tidb-lightning.toml
251+
```

0 commit comments

Comments
 (0)