Duplicating a MySQL table, indexes and data

How do I copy / clone / duplicate the data, structure and indexes of a MySQL table to a new one?

This is what I've found so far.

This will copy the data and the structure, but not the indexes:

create table {new_table} select * from {old_table};

This will copy the structure and indexes, but not the data:

create table {new_table} like {old_table};

To copy with indexes and triggers do these 2 queries:

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

To copy just structure and data use this one:

CREATE TABLE tbl_new AS SELECT * FROM tbl_old;

I've asked this before:

Copy a MySQL table including indexes


除了上面的解决方案之外,您可以使用AS将它AS到一行中。

CREATE TABLE tbl_new AS SELECT * FROM tbl_old;

Go to phpMyAdmin and select your original table then select " Operations " tab in the ' Copy table to (database.table) ' area select the database where you want to copy and add a name for your new table.

复制表 -  phyMyAdmin截图

链接地址: http://www.djcxy.com/p/38038.html

上一篇: MySQL中的模式/数据库之间的区别

下一篇: 复制MySQL表,索引和数据