Copy a MySQL table including indexes

2019-01-23 00:36发布

问题:

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?

回答1:

CREATE TABLE newtable LIKE oldtable; 
INSERT newtable SELECT * FROM oldtable;