How do I copy or clone or duplicate the data, structure, and indices of a MySQL table to a new one?
This is what I've found so far.
This will copy the data and the structure, but not the indices:
create table {new_table} select * from {old_table};
This will copy the structure and indices, but not the data:
create table {new_table} like {old_table};
To copy with indexes and triggers do these 2 queries:
CREATE TABLE new_table LIKE old_table;
INSERT INTO new_table SELECT * FROM old_table;
To copy just structure and data use this one:
CREATE TABLE new_table AS SELECT * FROM old_table;
I've asked this before:
Copy a MySQL table including indexes
Apart from the solution above, you can use AS
to make it in one line.
CREATE TABLE tbl_new AS SELECT * FROM tbl_old;
create table {new_table} select * from {old_table};
not an answer and provides no new information.
MySQL way:
CREATE TABLE recipes_new LIKE production.recipes;
INSERT recipes_new SELECT * FROM production.recipes;
Go to phpMyAdmin and select your original table then select "Operations" tab in the "Copy table to (database.table)" area. Select the database where you want to copy and add a name for your new table.
https://i.stack.imgur.com/3tQzC.jpg
I found the same situation and the approach which I took was as follows:
Execute SHOW CREATE TABLE
select *
will perform in huge tables.AUTO_INCREMENT
value.