1、复制表结构及数据到新表
create table new_table_name select * from old_table_name;
这种方法的一个最不好的地方就是新表中没有了旧表的primary key、Extra(auto_increment)等属性。
2、只复制表结构到新表
create table new_table_name select * from old_table_name where 1=2;
或
create table new_table_name like old_table_name;
3、复制旧表的数据到新表(假设两个表结构一样)
insert into new_table_name select * from old_table_name;
4、复制旧表的数据到新表(假设两个表结构不一样)
insert into new_table_name(字段1,字段2,字段3) select (字段1,字段2,字段3) from old_table_name;
5、表不在同一数据库中(如:db1 table1,db2 table2)
完全复制
insert into db1.table1 select * from db2.table2;
不复制重复记录
insert into db1.table1 selec