fbpx

Copy MySql specific table rows to another table

Copy MySql specific table rows to another table

The safest way to do it is to fully specify the columns both for insertion and extraction. 
You can copy the schema of the table by this command.

CREATE TABLE new_table LIKE old_table;

You can disable index building in start and enable indexes in end. This will speed up the process in cases of large tables.

ALTER TABLE new_table DISABLE KEYS;
insert into new_table (new_table.col1, new_table.col2, new_table.col3, cd) select old_table.col1, old_table.col2, old_table.col3 from old_table where id = 5;
ALTER TABLE new_table ENABLE KEYS;

You can also write a php script to get records and then insert into new table.

Share this post