MYSQL Copy Table

MYSQL Copy Table

So, you have a mySQL table and you want to copy it. Although there are various methods to copy a table, the one shown below will demonstrate how to copy a mysql table in its entirety, including all data and structure.

Not only will the code below preserve the data, it will maintain the autoincrement field if it exists.

create table tablename2 like tablename1;  
insert into tablename2 select * FROM tablename1;