复制一个MySQL表,包括索引。

时间:2022-09-16 10:12:59

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

我可以复制一个MySQL表来创建一个新的表:

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 个解决方案

#1


91  

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

#1


91  

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