Tag Archives: copying tables

Copying mysql tables with keys / extras

A lot of sites will tell you to do this:

CREATE TABLE t2 SELECT * FROM t1;

Problem is that you’ll lost your auto_increment, primary key and any other indexes you have (and any other extra meta data like that.)

This might not be the best solution, but hey it worked for me:

CREATE TABLE t2 LIKE t1;

INSERT INTO t2 SELECT * FROM t1;

Hope that helps somebody.. I only noticed I’d lost all my primary keys after copying a load of tables using the old method.