mysql 普通表转分区表
2015-08-06 15:41
711 查看
<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_log\G; *************************** 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
相关文章推荐
- MySQL Cluster初步学习资料整理--安装部署新特性性能测试等
- mysql-proxy 读写分离
- mysql Amoeba 配置
- mysql 误删root
- mysql 慢查询说明
- 安装mysql Install/Remove of the Service Denied!错误的解决办法
- mysql 查看数据大小语句
- MySQL 事件调度器创建
- [转载]Mysql导出表结构及表数据 mysqldump用法
- mysql 创建分区表注意事项,每一个唯一约束必须包含在Mysql分区表的分区键(也包括主键约束)。
- 学习MySQL协议的神器
- mysql备份
- mysql 命令行操作
- MySQL binlog手动和自动清除
- 19.1 Overview of Partitioning in MySQL
- Mysql的DATE_FORMAT()应用
- 【数据库】MySQL乱码解决(存入数据乱码和查询输出乱码)
- MySql - SQL Error (1130): Host IP is not allowed to connect to this MySQL server
- mysql远程登陆
- mysql中影响性能的全局变量