MySQL - How to Copy Table in MySQL Duplicate Structure, Data, and Indexes Correctly

How to Copy Table in MySQL: Duplicate Structure, Data, and Indexes Correctly

0 Shares
0
0
0

DBAs, developers, and analysts copy tables in MySQL dozens of times a day for various reasons. This tutorial shows you how to copy a MySQL table structure and data.

MySQL doesn’t have a copy table statement, so you’ll have to do it sideways. MySQL lets you clone tables three ways.

CREATE TABLE … AS SELECT statement to copy the source table column attributes and data.

CREATE TABLE new_table_name AS SELECT * FROM old_table_name;

CREATE TABLE … LIKE statement to create an empty table based on the definition of the original table, including column attributes and indexes.

CREATE TABLE new_table_name LIKE old_table_name;

SHOW CREATE TABLE to generate a create table script for the original table.

SHOW CREATE TABLE customer\G

Reference Click Here