mysql复制表结构或者表数据,可备份数据

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) 

猜你喜欢

转载自qiaolevip.iteye.com/blog/1977034