标签:copytable
1.复制表结构
CREATE TABLE dns_records1 SELECT * FROM dns_records WHERE 1=2
或者
CREATE TABLE dns_records2 LIKE dns_records
注意:前者不能复制表的主键和索引
2.跨库复制表结构
CREATE TABLE dbopv1.dns_records3 LIKE dbopv2.dns_records
或者
CREATE TABLE dbopv1.dns_records4 SELECT * FROM dbopv2.dns_records WHERE 1=2
注意:后者不能复制表的主键和索引
3.复制表结构及数据到新表
CREATE newtable SELECT * FROM oldtable
4.全表复制数据(两个表的结构一致)
INSERT INTO tableA SELECT * FROM tableB
5.根据条件复制数据(两个表的结构一致)
INSERT INTO tableA SELECT * FROM tableB WHERE xxx = xxx
6.根据条件复制数据(两个表的结构不一致)
INSERT INTO tableA (字段1,字段2,.......) SELECT 字段1,字段2,...... FROM tableB WHERE xxx = xxx
7.同一实例下跨库复制表记录
INSERT INTO database1.tableA
SELECT * FROM database2.tableB
WHERE .....
INSERT INTO dbopv1.dns_records SELECT * FROM dbopv2.dns_records WHERE `host` LIKE ‘%DBOP-K1‘;
标签:copytable
原文地址:http://kingbox.blog.51cto.com/3295899/1657910