mysql复制表结构和数据(mysql复制表结构和数据的关系)

mysql复制表结构和数据

只复制表结构

create table 表名 like 被复制的表名;

如:
mysql> create table test12 like test11;
Query OK, 0 rows affected (0.01 sec)

mysql> select * from test12;
Empty set (0.00 sec)

mysql> show create table test12;
+——–+——-+
| Table  | Create Table

+——–+——-+
| test12 | CREATE TABLE `test12` (
`a` int(11) NOT NULL AUTO_INCREMENT COMMENT ‘字段a’,
`b` int(11) NOT NULL COMMENT ‘字段b’,
PRIMARY KEY (`a`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8     |
+——–+——-+
1 row in set (0.00 sec)


复制表结构+数据

create table 表名 [as] select 字段,… from 被复制的表 [where 条件];

如:
mysql> create table test13 as select * from test11;
Query OK, 1 row affected (0.02 sec)
Records: 1  Duplicates: 0  Warnings: 0

mysql> select * from test13;
+—+—–+
| a | b   |
+—+—–+
| 1 | 100 |
+—+—–+
1 row in set (0.00 sec)

表结构和数据都过来了。

正文完
 0