65

I can copy a MySQL table to create a new table:

CREATE TABLE newtable SELECT * FROM oldtable

This works, but the indexes are not copied to the new table. How can I copy a table including the indexes?

TRiG
  • 9,687
  • 6
  • 54
  • 105
Haim Evgi
  • 120,002
  • 45
  • 212
  • 219
  • `indexes not create` vs `prevent the indexes` is ambiguous, what do you want to do? – Pentium10 Mar 10 '10 at 09:52
  • 5
    possible duplicate of [Duplicating a MySQL table, indexes and data](http://stackoverflow.com/questions/3280006/duplicating-a-mysql-table-indexes-and-data) – luchaninov Oct 01 '14 at 18:41
  • 4
    @luchaninov the answer on that question mentions this question. This is an infinite loop. – FrancescoMM Sep 20 '17 at 08:21

1 Answers1

127
CREATE TABLE newtable LIKE oldtable; 
INSERT INTO newtable SELECT * FROM oldtable;
Mojtaba
  • 4,536
  • 4
  • 19
  • 38
raveren
  • 17,078
  • 12
  • 66
  • 81