• 千万行的表怎么加索引


    执行过程如下(前提是停止写入防止数据异常)

    1、创建一个表结构和对象一样的表

    2、给新表加索引

    3、给新表插入老表数据

    4、把2个表重命名。

    5、删除重命名后老表(可做可不做)

    create table tmp like paper_author;
    ALTER TABLE tmp ADD INDEX ( `PaperID` )

    insert into tmp(ooo,...)  select  ooo,... from paper_author
    Query OK, 35510600 rows affected (9 min 24.99 sec)
    Records: 35510600  Duplicates: 0  Warnings: 0

    RENAME TABLE paper_author TO tmp2, tmp to paper_author;

    drop table tmp2;

    执行过程如下

    mysql> use seewoserzs;
    Database changed
    mysql> desc t_gameinfo;
    +----------+---------------------+------+-----+-------------------+----------------+
    | Field    | Type                | Null | Key | Default           | Extra          |
    +----------+---------------------+------+-----+-------------------+----------------+
    | gameid   | varchar(32)         | YES  | UNI | 10000             |                |
    | gamename | varchar(32)         | YES  |     | NULL              |                |
    | cpid     | bigint(20)          | YES  |     | NULL              |                |
    | gametype | varchar(20)         | YES  |     | NULL              |                |
    | addtime  | timestamp           | YES  |     | CURRENT_TIMESTAMP |                |
    | id       | bigint(20) unsigned | NO   | PRI | NULL              | auto_increment |
    +----------+---------------------+------+-----+-------------------+----------------+
    6 rows in set
    
    mysql> create table t1 like t_gameinfo;
    Query OK, 0 rows affected
    
    mysql> desc t1;
    +----------+---------------------+------+-----+-------------------+----------------+
    | Field    | Type                | Null | Key | Default           | Extra          |
    +----------+---------------------+------+-----+-------------------+----------------+
    | gameid   | varchar(32)         | YES  | UNI | 10000             |                |
    | gamename | varchar(32)         | YES  |     | NULL              |                |
    | cpid     | bigint(20)          | YES  |     | NULL              |                |
    | gametype | varchar(20)         | YES  |     | NULL              |                |
    | addtime  | timestamp           | YES  |     | CURRENT_TIMESTAMP |                |
    | id       | bigint(20) unsigned | NO   | PRI | NULL              | auto_increment |
    +----------+---------------------+------+-----+-------------------+----------------+
    6 rows in set
    
    mysql> insert into t1 select * from t_gameinfo;
    Query OK, 34 rows affected
    Records: 34  Duplicates: 0  Warnings: 0
    
    mysql> rename table t_gameinfo to t2 ,t1 to t_gameinfo;
    Query OK, 0 rows affected
    
    mysql> 
    

      

  • 相关阅读:
    史上最简单易懂的Android Pad手机屏幕适配方案
    Android平板开发
    Android TV 开发 (1)
    三大开源java区块链库
    将博客园数据导出到wordpress
    MQTT结构分析
    netty+mqtt
    安卓原生 VideoView实现rtsp流媒体的播放
    【矩阵专题】——矩阵加速
    征战蓝桥 —— 2016年第七届 —— C/C++A组第4题——快速排序
  • 原文地址:https://www.cnblogs.com/nmap/p/6683119.html
Copyright © 2020-2023  润新知