# Creating table clone when running cluster

**URL:** <https://forums.percona.com/t/creating-table-clone-when-running-cluster/15192>\
**Category:** Percona XtraDB Cluster 8.x\
**Tags:** mysql, percona\
**Created:** [April 11, 2022, 3:45pm UTC](https://forums.percona.com/t/creating-table-clone-when-running-cluster/15192 "2022-04-11T15:45:47Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![koei934](https://avatars.discourse-cdn.com/v4/letter/k/e56c9b/32.png) [@koei934](https://forums.percona.com/u/koei934)\
**Post date:** [April 11, 2022, 3:45pm UTC](https://forums.percona.com/t/creating-table-clone-when-running-cluster/15192/1 "2022-04-11T15:45:47Z")

</div>

Hi!

I’m trying to create a specific table “clone” in a cluster. I have imported a database with ~100 tables and because I’d like to import new data into one of the tables called _mails_, I have to make a backup of that table first in case that anything goes wrong. So I tried to use two different approaches, but the first one fails after some time after starting processing and the second one is not appropriate for cluster - PXC strict mode.

Here is the first approach …

```auto
CREATE TABLE mails_tmp LIKE mails;
INSERT INTO mails_tmp SELECT * FROM mails;

```

… which works well, but after approximately 10 minutes in processing, I always get this error: **ERROR 1213 (40001): Deadlock found when trying to get lock; try restarting transaction**.

Second approach would be …

```auto
CREATE TABLE mails_test AS (SELECT * FROM mails);

```

… but due to the PXC strict mode, it is not possible - **ERROR 1105 (HY000): Percona-XtraDB-Cluster prohibits use of CREATE TABLE AS SELECT with pxc\_strict\_mode = ENFORCING or MASTER**.

I have not worked with cluster before but I’d like to move the application along with database to K8s since there are certain benefits which this environment would introduce. Currently I’m testing the migration locally and this cloning of table is part of the process, to test app with different set of data.

What am I doing wrong or is there any other way of doing this table clone?

Thank you for help!

---

<div class="post-metadata">

**Author:** ![matthewb](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.percona.com/matthewb/32/34_2.png) [@matthewb](https://forums.percona.com/u/matthewb)\
**Post date:** [April 11, 2022, 6:22pm UTC](https://forums.percona.com/t/creating-table-clone-when-running-cluster/15192/2 "2022-04-11T18:22:39Z")

</div>

Hello @koei934,  
Run the CREATE TABLE LIKE as you have done, then use `pt-table-sync` to copy the rows from original to new. This tool will copy the rows in chunks, which will help prevent the deadlock issue you are seeing. Or you can do this yourself by repeating INSERT and WHERE primaryKey BETWEEN X and Y queries.
