You can clone or create an exact copy of a table in MySQL
or MariaDB
by creating a new table with the same structure as the source and to copy over the data or rows of the source table to the new table.
This could be done manually or you could use some SQL
statements to easily clone or create a copy of an existing MySQL
/MariaDB
.
Steps to clone or copy a MySQL/MariaDB table:
Go to the database of the source table.
use mydatabase;
Create a table with same structure as the source/existing table.
CREATE TABLE new_table LIKE source_table;
This will just create a new, empty table and does not copy the followings;
Foreign key definitions
DATA DIRECTORY
INDEX DIRECTORY
Data
Copy the data from the source table using
SELECT
and
INSERT
statement after the table is created.
INSERT INTO new_table SELECT * FROM source_table;
Author:
Mohd Shakir Zakaria Cloud architect by profession but always consider himself as a developer, entrepreneur and an opensource enthusiast.
Discuss the article:
Comment anonymously. Login not required.