欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

mysql复制表结构或者表数据,可备份数据 博客分类: mysql 乔乐共享mysql表结构复制备份 

程序员文章站 2024-03-26 11:07:17
...
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)