mysql复制表结构 mysql复制表数据

发布时间:2020-06-16编辑:脚本学堂
本文介绍了mysql复制表结构与复制表数据的方法,mysql数据库中表结构与表数据的复制示例,有需要的朋友参考下。

mysql复制表结构 mysql复制表数据
 

复制代码 代码示例:
1)If the destination table already exists, use INSERT ... SELECT to copy the result set into it. For example, if dst_tbl contains an integer column i and a string column s, the following statement copies rows from src_tbl into dst_tbl, assigning column val to i and column name to s: 
INSERT INTO dst_tbl (i, s) SELECT val, name FROM src_tbl; 
 
2) 
mysql> create table a like users;   //复制表结构   
Query OK, 0 rows affected (0.50 sec)   
   
mysql> show tables;   
+----------------+   
| Tables_in_test |   
+----------------+   
| a              |   
| users          |   
+----------------+   
2 rows in set (0.00 sec) 
 
3)mysql> create table b select * from users limit 0; //复制表结构   
Query OK, 0 rows affected (0.00 sec)   
Records: 0  Duplicates: 0  Warnings: 0   
   
mysql> show tables;   
+----------------+   
| Tables_in_test |   
+----------------+   
| a              |   
| b              |   
| users          |   
+----------------+   
3 rows in set (0.00 sec)