Duplicating a MySQL table, indices, and data

前端 未结 12 1270
天涯浪人
天涯浪人 2020-11-27 08:42

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

This is what I\'ve found so far.

This will copy the data

12条回答
  •  醉酒成梦
    2020-11-27 09:13

    To copy with indexes and triggers do these 2 queries:

    CREATE TABLE newtable LIKE oldtable; 
    INSERT INTO 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

提交回复
热议问题