zoukankan      html  css  js  c++  java
  • mysql

    #复制表结构到新表
    对于mysql的复制相同表结构方法,有create table as 和create table like 两种,区别是什么呢?
        create table t2 as select * from t1 where 1=2 ; 或者 limit 0;
    as创建出来的t2表(新表)缺少t1表(源表)的索引信息,只有表结构相同,没有索引。
        create table t2 like t1 ;
    like 创建出来的新表包含源表的完整表结构和索引信息
    二者的用途:
        as用来创建相同表结构并复制源表数据
        like用来创建完整表结构和全部索引


    #复制记录
    从不同的表复制
    insert into tabel_1 select * from tabel_2 where id =X ;
    同一张表中复制(无主键)
    insert into tabel_1 select * from tabel_1 where id =X ;
    同一张表中复制(有主键)
    insert into tabel_1(field_1,field_2,field_3) select field_1,field_2,field_3 from tabel_1 where id= X ; 


    #导出数据
    mysqldump -h localhost -uroot -p123456  -d database > dump.sql //导出整个数据库结构(不包含数据)
    mysqldump -h localhost -uroot -p123456  -d database table > dump.sql //导出单个数据表结构(不包含数据)


    #导入数据
    mysql -h localhost -uroot -p123456  -d database < dump.sql //导入数据
    mysql -uroot -p123456 -h localhost database //连接数据库


    //时间戳
    select unix_timestamp('2013-01-01 10:10:10');
    select from_unixtime(1355272360);


    //组内排序
    SELECT * FROM (SELECT * FROM table1 WHERE `is_updated` = 1  ORDER BY product_id DESC) AS gtt GROUP by series_id


    select * from table1 t  left join (select * from table2 order by id desc) ts on (t.id = ts.transaction_id) where t.payment_method_id = 1
  • 相关阅读:
    Node 修改默认镜像源
    Mac下apache虚拟主机配置
    Grep命令出现 Binary file (standard input) matches
    idea取出方法参数提示
    Java8 Optional用法
    Codeforces Round #638 (Div. 2)
    Codeforces Round #637 (Div. 2)
    Codeforces Round #636 (Div. 3)
    Tree
    Educational Codeforces Round 85
  • 原文地址:https://www.cnblogs.com/fonyer/p/8871438.html
Copyright © 2011-2022 走看看