码迷,mamicode.com
首页 > 数据库 > 详细

mysql 复制表结构 / 从结果中导入数据到新表

时间:2017-06-21 09:38:08      阅读:203      评论:0      收藏:0      [点我收藏+]

标签:like   复制表   ica   div   default   root   rom   复制   localhost   

这只会复制结构:

mysql> create table a like mysql1;
Query OK, 0 rows affected (0.03 sec)

mysql> desc a;
+----------+----------+------+-----+---------+-------+
| Field    | Type     | Null | Key | Default | Extra |
+----------+----------+------+-----+---------+-------+
| user     | char(80) | NO   |     |         |       |
| host     | char(60) | NO   |     |         |       |
| password | char(41) | NO   |     |         |       |
+----------+----------+------+-----+---------+-------+
3 rows in set (0.00 sec)

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

mysql>

 

这除了复制结构, 还会复制结果集:

mysql> create table t8 select user,host from mysql.user;
Query OK, 1 row affected (0.03 sec)
Records: 1  Duplicates: 0  Warnings: 0

mysql> desc t8;
+-------+----------+------+-----+---------+-------+
| Field | Type     | Null | Key | Default | Extra |
+-------+----------+------+-----+---------+-------+
| user  | char(80) | NO   |     |         |       |
| host  | char(60) | NO   |     |         |       |
+-------+----------+------+-----+---------+-------+
2 rows in set (0.01 sec)

mysql> select * from t8;
+------+-----------+
| user | host      |
+------+-----------+
| root | localhost |
+------+-----------+
1 row in set (0.00 sec)

mysql>

 

mysql 复制表结构 / 从结果中导入数据到新表

标签:like   复制表   ica   div   default   root   rom   复制   localhost   

原文地址:http://www.cnblogs.com/perl6/p/7057683.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!