MySQL 复制已存在的表生成新表

从已有的表创建一个新的空表

CREATE TABLE new_table LIKE old_table;

注意: create table ... like 创建的表会保留原有表的字段、索引的定义,但不会保留外键的定义。

向空表插入数据

INSERT INTO new_table SELECT * FROM old_table;

参考链接:Create table in MySQL that matches another table? - Stack Overflow

原文地址:https://www.cnblogs.com/imzhi/p/create-table-in-mysql-that-matches-another-table.html