如何复制、克隆或复制数据、结构、,并将MySQL表的索引转换为新表?

这是我到目前为止发现的。

这将复制数据和结构,但不包括指数:

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

这将复制结构和索引,但不包括数据:

create table {new_table} like {old_table};

当前回答

MySQL方式:

CREATE TABLE recipes_new LIKE production.recipes;
INSERT recipes_new SELECT * FROM production.recipes;

其他回答

转到phpMyAdmin并选择原始表,然后在“复制表到(database.table)”区域中选择“操作”选项卡。选择要复制的数据库并为新表添加名称。

// To copy specific column data use this one:
CREATE TABLE ut_axis_existrec LIKE ut_karvy_annexure; // To create new table

INSERT INTO ut_axis_existrec
(funding_ac,micr_no, warrant_no,
amount,invname,mfundcode,funding_dt,status,remarks1,amc_remark,created_at) 
SELECT  
t1.funding_ac,
t1.micr_no,
t1.warrant_no,
t1.amount,
t1.invname,
t1.mfund_code,
t1.funding_dt,
t1.status,
t1.remarks1,
t1.created_at
from ut_axis_karvy
inner join 
ut_axis_karvy_master as t2
on t1.micr_no = t2.micr_no;

值得一提的是,检查表之前是否已存在尝试复制它:

CREATE TABLE IF NOT EXISTS new_table LIKE old_table;

INSERT new_table
SELECT * FROM old_table;

正如前面的回答所说,这将复制结构、数据和表的所有从属对象。

请参见MySql教程:

试试看:

`CREATE TABLE new-table (id INT(11) auto_increment primary key) SELECT old-table.name, old-table.group, old-table.floor, old-table.age from old-table;`

我从旧表中选择了4列,并制作了一个新表。

要使用索引和触发器进行复制,请执行以下两个查询:

CREATE TABLE new_table LIKE old_table; 
INSERT INTO new_table SELECT * FROM old_table;

要仅复制结构和数据,请使用以下方法:

CREATE TABLE new_table AS SELECT * FROM old_table;

我以前问过这个问题:

复制包含索引的MySQL表