mysql> CREATE  TABLE t1  ( id INT, date DATETIME DEFAULT CURRENT_TIMESTAMP) ENGINE=Innodb;
Query OK, rows affected mysql> insert into t1 values(, '2013-05-23 12:59:39');
Query OK, row affected mysql> insert into t1 values(, '2013-05-23 12:59:43');
insert into t1 values(, '2013-05-23 12:59:44');
insert into t1 values(, '2013-07-04 19:35:45');
insert into t1 values(, '2014-04-04 19:35:45' );
insert into t1 values(, '2014-05-04 19:35:45' );
insert into t1 values(, '2015-05-04 19:35:45');
insert into t1 values(, '2015-05-05 19:35:45');
insert into t1 values(, '2017-05-05 19:35:45');
insert into t1 values(,'2018-05-05 19:35:45' );
Query OK, row affected Query OK, row affected Query OK, row affected Query OK, row affected Query OK, row affected Query OK, row affected Query OK, row affected Query OK, row affected Query OK, row affected mysql> select * from t1;
+----+---------------------+
| id | date |
+----+---------------------+
| | -- :: |
| | -- :: |
| | -- :: |
| | -- :: |
| | -- :: |
| | -- :: |
| | -- :: |
| | -- :: |
| | -- :: |
| | -- :: |
+----+---------------------+
rows in set mysql> explain select * from t1;
+----+-------------+-------+------+---------------+------+---------+------+------+-------+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
+----+-------------+-------+------+---------------+------+---------+------+------+-------+
| | SIMPLE | t1 | ALL | NULL | NULL | NULL | NULL | | NULL |
+----+-------------+-------+------+---------------+------+---------+------+------+-------+
row in set mysql> EXPLAIN SELECT * FROM t1 WHERE date >= '2014-03-05 19:00:12' AND date <= '2016-03-05 18:45:12';
+----+-------------+-------+------+---------------+------+---------+------+------+-------------+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
+----+-------------+-------+------+---------------+------+---------+------+------+-------------+
| | SIMPLE | t1 | ALL | NULL | NULL | NULL | NULL | | Using where |
+----+-------------+-------+------+---------------+------+---------+------+------+-------------+
row in set mysql> CREATE TABLE t2 ( id INT, date DATETIME DEFAULT CURRENT_TIMESTAMP) ENGINE=Innodb
PARTITION BY RANGE (YEAR(date)) (
PARTITION p2013 VALUES LESS THAN(),
PARTITION p2014 VALUES LESS THAN(),
PARTITION p2015 VALUES LESS THAN(),
PARTITION p2016 VALUES LESS THAN(),
PARTITION p2017 VALUES LESS THAN(),
PARTITION p2099 VALUES LESS THAN MAXVALUE
) ;
Query OK, rows affected mysql> show create table t2;
+-------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Table | Create Table |
+-------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| t2 | CREATE TABLE `t2` (
`id` int() DEFAULT NULL,
`date` datetime DEFAULT CURRENT_TIMESTAMP
) ENGINE=InnoDB DEFAULT CHARSET=utf8
/*!50100 PARTITION BY RANGE (YEAR(date))
(PARTITION p2013 VALUES LESS THAN (2014) ENGINE = InnoDB,
PARTITION p2014 VALUES LESS THAN (2015) ENGINE = InnoDB,
PARTITION p2015 VALUES LESS THAN (2016) ENGINE = InnoDB,
PARTITION p2016 VALUES LESS THAN (2017) ENGINE = InnoDB,
PARTITION p2017 VALUES LESS THAN (2018) ENGINE = InnoDB,
PARTITION p2099 VALUES LESS THAN MAXVALUE ENGINE = InnoDB) */ |
+-------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
row in set mysql> SELECT table_name,partition_name,table_rows FROM information_schema.PARTITIONS WHERE table_schema=database() AND table_name='t2';
+------------+----------------+------------+
| table_name | partition_name | table_rows |
+------------+----------------+------------+
| t2 | p2013 | |
| t2 | p2014 | |
| t2 | p2015 | |
| t2 | p2016 | |
| t2 | p2017 | |
| t2 | p2099 | |
+------------+----------------+------------+
rows in set mysql> EXPLAIN SELECT * FROM t2;
+----+-------------+-------+------+---------------+------+---------+------+------+-------+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
+----+-------------+-------+------+---------------+------+---------+------+------+-------+
| | SIMPLE | t2 | ALL | NULL | NULL | NULL | NULL | | NULL |
+----+-------------+-------+------+---------------+------+---------+------+------+-------+
row in set mysql> insert into t2 select * from t1;
Query OK, rows affected
Records: Duplicates: Warnings: mysql> explain select * from t2;
+----+-------------+-------+------+---------------+------+---------+------+------+-------+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
+----+-------------+-------+------+---------------+------+---------+------+------+-------+
| | SIMPLE | t2 | ALL | NULL | NULL | NULL | NULL | | NULL |
+----+-------------+-------+------+---------------+------+---------+------+------+-------+
row in set mysql> select * from t2;
+----+---------------------+
| id | date |
+----+---------------------+
| | -- :: |
| | -- :: |
| | -- :: |
| | -- :: |
| | -- :: |
| | -- :: |
| | -- :: |
| | -- :: |
| | -- :: |
| | -- :: |
+----+---------------------+
rows in set mysql> SELECT table_name,partition_name,table_rows FROM information_schema.PARTITIONS WHERE table_schema=database() AND table_name='t2';
+------------+----------------+------------+
| table_name | partition_name | table_rows |
+------------+----------------+------------+
| t2 | p2013 | |
| t2 | p2014 | |
| t2 | p2015 | |
| t2 | p2016 | |
| t2 | p2017 | |
| t2 | p2099 | |
+------------+----------------+------------+
rows in set mysql> EXPLAIN PARTITIONS SELECT * FROM t2 WHERE date >= '2014-03-05 19:00:12' AND date <= '2016-03-05 18:45:12';
+----+-------------+-------+-------------------+------+---------------+------+---------+------+------+-------------+
| id | select_type | table | partitions | type | possible_keys | key | key_len | ref | rows | Extra |
+----+-------------+-------+-------------------+------+---------------+------+---------+------+------+-------------+
| | SIMPLE | t2 | p2014,p2015,p2016 | ALL | NULL | NULL | NULL | NULL | | Using where |
+----+-------------+-------+-------------------+------+---------------+------+---------+------+------+-------------+
row in set mysql>
 
    SELECT *
    FROM tb_common_biz
    PARTITION (p201707);
 
 
如果可以通过代码确定使用的PARTITION,可以这样查:
SELECT * FROM B PARTITION(p1)
 
数据插入完成后,要验证是否对应id的数据保存在了对应的分区,可以使用查询分区的命令,如下:
 
SELECT partition_name,partition_expression,partition_description,table_rows
FROM information_schema.PARTITIONS
WHERE table_schema = SCHEMA() AND table_name='tb_common_biz'
 
 
 
 
 
 
DROP TABLE IF EXISTS `tb_common_biz`;
CREATE TABLE `tb_common_biz` (
  `data_id` bigint(20) NOT NULL,
  `data_category` varchar(32) DEFAULT NULL,
  `service_type` varchar(32) DEFAULT NULL,
  `group_id` varchar(32) DEFAULT NULL,
  `group_name` varchar(64) DEFAULT NULL,
  `create_person_id` varchar(16) DEFAULT NULL,
  `create_person_name` varchar(64) DEFAULT NULL,
  `create_person_telno` varchar(32) DEFAULT NULL,
  `create_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  `update_person` varchar(16) DEFAULT NULL,
  `update_time` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00',
  `result` varchar(256) DEFAULT NULL,
  `result_ext` varchar(256) DEFAULT NULL,
  `service_owner` varchar(64) DEFAULT NULL,
  `process_instance_id` varchar(64) DEFAULT NULL,
  `task_id` varchar(64) DEFAULT NULL,
  `ext_activiti_info` varchar(256) DEFAULT NULL,
  `status` varchar(256) DEFAULT NULL,
  `ext_status` varchar(256) DEFAULT NULL,
  `data1` varchar(1024) DEFAULT NULL,
  `data2` varchar(1024) DEFAULT NULL,
  `data3` varchar(1024) DEFAULT NULL,
  `data4` varchar(1024) DEFAULT NULL,
  `data5` varchar(1024) DEFAULT NULL,
  `data6` varchar(1024) DEFAULT NULL,
  `data7` varchar(1024) DEFAULT NULL,
  `data8` varchar(1024) DEFAULT NULL,
  `data9` varchar(1024) DEFAULT NULL,
  `data10` varchar(1024) DEFAULT NULL,
  PRIMARY KEY (`data_id`)
)
PARTITION BY RANGE (data_id) (
PARTITION p201704 VALUES LESS THAN (2017050100010000001),
PARTITION p201705 VALUES LESS THAN (2017060100010000001),
PARTITION p201706 VALUES LESS THAN (2017070100010000001),
PARTITION p201707 VALUES LESS THAN (2017080100010000001),
PARTITION p201708 VALUES LESS THAN (2017090100010000001),
PARTITION p201709 VALUES LESS THAN (2017100100010000001),
PARTITION p201710 VALUES LESS THAN (2017110100010000001),
PARTITION p201711 VALUES LESS THAN (2017120100010000001),
PARTITION p201712 VALUES LESS THAN (2018010100010000001),
PARTITION p201801 VALUES LESS THAN (2018020100010000001),
PARTITION p201802 VALUES LESS THAN (2018030100010000001),
PARTITION p201803 VALUES LESS THAN (2018040100010000001),
PARTITION p201804 VALUES LESS THAN (2018050100010000001),
PARTITION p201805 VALUES LESS THAN (2018060100010000001),
PARTITION p201806 VALUES LESS THAN (2018070100010000001),
PARTITION p201807 VALUES LESS THAN (2018080100010000001),
PARTITION p201808 VALUES LESS THAN (2018090100010000001),
PARTITION p201809 VALUES LESS THAN (2018100100010000001),
PARTITION p201810 VALUES LESS THAN (2018110100010000001),
PARTITION p201811 VALUES LESS THAN (2018120100010000001),
PARTITION p201812 VALUES LESS THAN (2019010100010000001),
PARTITION p2019 VALUES LESS THAN (MAXVALUE) )
;

mysql 5.6 分区与不分区的区别的更多相关文章

  1. MySQL学习笔记十三:表分区

    1.分区一般用于非常大的表,采用“分而治之”的策略,将一个很大的对象分成多个小对象进行管理,每个分区都是一个独立的对象. 分区使用分区键将数据根据范围值,特定列值或HASH值等规则分布在不同的分区中. ...

  2. Mysql --分区(4)List分区

    LIST分区 LIST分区是建立离散的值列表告诉数据库特定的值属于哪个分区,LIST分区在很多方面类似于RANGE分区,区别在LIST分区是从属于一个枚举列表的值得集合,RANGE分区是从属于一个连续 ...

  3. Mysql --分区(3)range分区

    3.分区类型 RANGE分区 按照range分区的表是利用取值范围将数据分成分区,区间要连续并且不能互相重叠,使用values less than操作符进行分区定义 CREATE TABLE tnp ...

  4. mysql的分区技术(建立分区)

    -- mysql建立表分区,使用range方法建立: create table t_range( id int(11), money int(11) unsigned not null, date d ...

  5. mysql表分区、查看分区

    原文地址:http://blog.csdn.net/feihong247/article/details/7885199 一.       mysql分区简介 数据库分区 数据库分区是一种物理数据库设 ...

  6. mysql分区之range分区

    随着互联网的发展,各方面的数据越来越多,从最近两年大数据越来越强的呼声中就可见一斑. 我们所做的项目虽算不上什么大项目,但是由于业务量的问题,数据也是相当的多. 数据一多,就很容易出现性能问题,而为了 ...

  7. MySQL 横向表分区之RANGE分区小结

    MySQL 横向表分区之RANGE分区小结 by:授客 QQ:1033553122 目录 简介 1 RANGE分区 1 创建分区表 1 查看表分区 2 新增表分区 2 新增数据 3 分区表查询 3 删 ...

  8. mysql数据库优化(三)--分区

    mysql的分区,分表 分区:把一个数据表的文件和索引分散存储在不同的物理文件中. 特点:业务层透明,无需任何修改,即使从新分表,也是在mysql层进行更改(业务层代码不动) 分表:把原来的表根据条件 ...

  9. mysql 表分区 查看表分区 修改表分区

    原文地址:http://blog.csdn.net/feihong247/article/details/7885199 一.       mysql分区简介 数据库分区 数据库分区是一种物理数据库设 ...

  10. mysql分区表之二:MySQL的表的四种分区类型介绍

    一.什么是表分区 通俗地讲表分区是将一大表,根据条件分割成若干个小表.mysql5.1开始支持数据表分区了.如:某用户表的记录超过了600万条,那么就可以根据入库日期将表分区,也可以根据所在地将表分区 ...

随机推荐

  1. Mysql thread 与 OS thread

    测试环境信息如下: OS:Ubuntu 16.04 LTS Mysql:Mysql 5.7.18,使用docker images运行的实例 Mysql如何处理client请求 在Mysql中,连接管理 ...

  2. [knowledge] big data things

    http://hadoop.apache.org/ https://spark.apache.org/ https://nifi.apache.org/ https://www.cloudera.co ...

  3. 12.2RAC搭建记录

    12.2RAC环境搭建记录 安装前资源检查 资源限制要求/etc/security/limits.conf Table 6-1 Installation Owner Resource Limit Re ...

  4. jquery基础学习之动画篇(四)

    一,动画效果 hide() show() 隐藏与显示 hide(options) 隐藏 对应display:none,有参数就会变成动画, $(document).click(function () ...

  5. kubernetes的Controller Manager

    1. Controller Manager简介 Controller Manager作为集群内部的管理控制中心,负责集群内的Node.Pod副本.服务端点(Endpoint).命名空间(Namespa ...

  6. java Scanner和Random的Demo

    import java.util.Scanner;//导入包 import java.util.Random; public class ScannerDemo{ public static void ...

  7. 洛谷P3602 Koishi Loves Segments 贪心

    正解:贪心 解题报告: 传送门! 首先在学习贪心的入门题的时候我们就知道,当x=1的时候,也就是每条线段不能相交的时候的做法——就按右端点排序然后能选就选,也就是会议安排问题,原因显然?就你选右端点更 ...

  8. 天梯赛训练2 7-8 矩阵A乘以B

    知道矩阵A*B的规则按照规则来做就好了 #include <bits/stdc++.h>#include <stdio.h>using namespace std;int a[ ...

  9. nodejs 学习四 处理回调地狱

    面对下面回调,你面对这样代码,你心里难道不百万只羊驼吗? nodejs 提供了util.promisify方法,来解决这类问题.(类似es6 种是提供了Promise的方法). const fs = ...

  10. intellij idea建立maven项目

    配置jdk 配置mvn http://jingyan.baidu.com/article/d8072ac45d3660ec94cefd51.html 右键“计算机”,选择“属性”,之后点击“高级系统设 ...