zoukankan      html  css  js  c++  java
  • mysql 普通表转分区表

    <pre name="code" class="sql"> CREATE TABLE `history_log` (
      `id` bigint(20) unsigned NOT NULL,
      `itemid` bigint(20) unsigned NOT NULL,
      `clock` int(11) NOT NULL DEFAULT '0',
      `timestamp` int(11) NOT NULL DEFAULT '0',
      `source` varchar(64) NOT NULL DEFAULT '',
      `severity` int(11) NOT NULL DEFAULT '0',
      `value` text NOT NULL,
      `logeventid` int(11) NOT NULL DEFAULT '0',
      `ns` int(11) NOT NULL DEFAULT '0',
      PRIMARY KEY (`id`),
      UNIQUE KEY `history_log_2` (`itemid`,`id`),
      KEY `history_log_1` (`itemid`,`clock`)
    ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
    
    alter table history_log partition by RANGE (clock)
    (PARTITION  p20150806 values less than (20150807));
    
    mysql> alter table history_log partition by RANGE (clock)
        -> (PARTITION  p20150806 values less than (20150807));
    ERROR 1503 (HY000): A PRIMARY KEY must include all columns in the table's partitioning function
    
    主键必须包含分区键:
    
    mysql>  CREATE TABLE `history_log` (
        ->   `id` bigint(20) unsigned NOT NULL,
        ->   `itemid` bigint(20) unsigned NOT NULL,
        ->   `clock` int(11) NOT NULL DEFAULT '0',
        ->   `timestamp` int(11) NOT NULL DEFAULT '0',
        ->   `source` varchar(64) NOT NULL DEFAULT '',
        ->   `severity` int(11) NOT NULL DEFAULT '0',
        ->   `value` text NOT NULL,
        ->   `logeventid` int(11) NOT NULL DEFAULT '0',
        ->   `ns` int(11) NOT NULL DEFAULT '0',
        ->   PRIMARY KEY (`id`,`clock`),
        ->   UNIQUE KEY `history_log_2` (`itemid`,`id`),
        ->   KEY `history_log_1` (`itemid`,`clock`)
        -> ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
    Query OK, 0 rows affected (0.03 sec)
    
    mysql> alter table history_log partition by RANGE (clock)
        -> (PARTITION  p20150806 values less than (20150807));
    ERROR 1503 (HY000): A UNIQUE INDEX must include all columns in the table's partitioning function
    
    
    唯一索引也得包含分区键:
     CREATE TABLE `history_log` (
      `id` bigint(20) unsigned NOT NULL,
      `itemid` bigint(20) unsigned NOT NULL,
      `clock` int(11) NOT NULL DEFAULT '0',
      `timestamp` int(11) NOT NULL DEFAULT '0',
      `source` varchar(64) NOT NULL DEFAULT '',
      `severity` int(11) NOT NULL DEFAULT '0',
      `value` text NOT NULL,
      `logeventid` int(11) NOT NULL DEFAULT '0',
      `ns` int(11) NOT NULL DEFAULT '0',
      PRIMARY KEY (`id`,`clock`),
      UNIQUE KEY `history_log_2` (`itemid`,`id`,`clock`),
      KEY `history_log_1` (`itemid`,`clock`)
    ) ENGINE=InnoDB DEFAULT CHARSET=utf8
    partition by RANGE (clock)  (PARTITION  p20150806 values less than (20150807));
    ---------------------------------------------------------------------------------
    mysql>  CREATE TABLE `history_log` (
        ->   `id` bigint(20) unsigned NOT NULL,
        ->   `itemid` bigint(20) unsigned NOT NULL,
        ->   `clock` int(11) NOT NULL DEFAULT '0',
        ->   `timestamp` int(11) NOT NULL DEFAULT '0',
        ->   `source` varchar(64) NOT NULL DEFAULT '',
        ->   `severity` int(11) NOT NULL DEFAULT '0',
        ->   `value` text NOT NULL,
        ->   `logeventid` int(11) NOT NULL DEFAULT '0',
        ->   `ns` int(11) NOT NULL DEFAULT '0',
        ->   PRIMARY KEY (`id`,`clock`),
        ->   UNIQUE KEY `history_log_2` (`itemid`,`id`,`clock`),
        ->   KEY `history_log_1` (`itemid`,`clock`)
        -> ) ENGINE=InnoDB DEFAULT CHARSET=utf8
        -> partition by RANGE (clock)  (PARTITION  p20150806 values less than (20150807));
    Query OK, 0 rows affected (0.03 sec)
    
    mysql> desc history_log;
    +------------+---------------------+------+-----+---------+-------+
    | Field      | Type                | Null | Key | Default | Extra |
    +------------+---------------------+------+-----+---------+-------+
    | id         | bigint(20) unsigned | NO   | PRI | NULL    |       |
    | itemid     | bigint(20) unsigned | NO   | MUL | NULL    |       |
    | clock      | int(11)             | NO   | PRI | 0       |       |
    | timestamp  | int(11)             | NO   |     | 0       |       |
    | source     | varchar(64)         | NO   |     |         |       |
    | severity   | int(11)             | NO   |     | 0       |       |
    | value      | text                | NO   |     | NULL    |       |
    | logeventid | int(11)             | NO   |     | 0       |       |
    | ns         | int(11)             | NO   |     | 0       |       |
    +------------+---------------------+------+-----+---------+-------+
    9 rows in set (0.01 sec)
    
    mysql> show create table history_logG;
    *************************** 1. row ***************************
           Table: history_log
    Create Table: CREATE TABLE `history_log` (
      `id` bigint(20) unsigned NOT NULL,
      `itemid` bigint(20) unsigned NOT NULL,
      `clock` int(11) NOT NULL DEFAULT '0',
      `timestamp` int(11) NOT NULL DEFAULT '0',
      `source` varchar(64) NOT NULL DEFAULT '',
      `severity` int(11) NOT NULL DEFAULT '0',
      `value` text NOT NULL,
      `logeventid` int(11) NOT NULL DEFAULT '0',
      `ns` int(11) NOT NULL DEFAULT '0',
      PRIMARY KEY (`id`,`clock`),
      UNIQUE KEY `history_log_2` (`itemid`,`id`,`clock`),
      KEY `history_log_1` (`itemid`,`clock`)
    ) ENGINE=InnoDB DEFAULT CHARSET=utf8
    /*!50100 PARTITION BY RANGE (clock)
    (PARTITION p20150806 VALUES LESS THAN (20150807) ENGINE = InnoDB) */
    1 row in set (0.00 sec)
    
    ERROR: 
    No query specified


    
                                        
    
  • 相关阅读:
    应用Solaris11放置光盘修复solaris引导妨碍
    HP 3803TX 装置debian4 Linux
    释放linux细碎的内存
    linux批量查找文件内容
    Oracle 10g R2 for Solaris x86在Solaris 11上的装配
    Linux 零碎进修之shell剧本进修
    华硕易PC台式机版7月环球上市 或运转Linux
    Linux文件琐细 一分钱一分货
    linux下平安管理
    预装Windows或Ubuntu,戴尔出Mini Inspiron 8.9寸笔记本
  • 原文地址:https://www.cnblogs.com/hzcya1995/p/13351481.html
Copyright © 2011-2022 走看看