How to Clone a MySQL Table

Cloning a MySQL table involves two separate commands. One command will duplicate the columns and structure to a new table, and the other command will copy over the data and indexes.

1. First, create a new table that adheres to the same structure as the table you’d like to clone.

CREATE TABLE table_clone LIKE table_original;

2. Next, copy over the data from your original table into the cloned table.

INSERT table_clone SELECT * FROM table_original;

You should now have two identical tables, right down to the data, indexes, primary key, column structure, and everything else.

Leave a Reply

Your email address will not be published. Required fields are marked *