zoukankan      html  css  js  c++  java
  • mysql 复制表结构 / 从结果中导入数据到新表

    这只会复制结构:

    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>
    

     用法例子:

    #创一个一样的表
    create table a_back like mysql.user;
    
    #导入另一个表中的所有数据
    
    insert into a_back select * from mysql.user;
    
  • 相关阅读:
    ubuntu下安装VMware tools
    ubuntu 输入su提示认证失败的解决方法
    Squishy Bird 压扁小鸟
    js 毫秒转日期(yy-MM-dd hh:mm:ss)
    js--使用构造器函数来新建对象及操作
    css中table样式
    js 字符串截取
    JavaScript中Math--random()/floor()/round()/ceil()
    canvas draw a image
    html5 canvas simple drawing
  • 原文地址:https://www.cnblogs.com/perl6/p/7057683.html
Copyright © 2011-2022 走看看