检查的Mysql是否支持partition
(root@localhost)[(none)]SHOW PLUGINS;
+----------------------------+----------+--------------------+---------+---------+
| Name | Status | Type | Library | License |
+----------------------------+----------+--------------------+---------+---------+
| binlog | ACTIVE | STORAGE ENGINE | NULL | GPL |
| mysql_native_password | ACTIVE | AUTHENTICATION | NULL | GPL |
| sha256_password | ACTIVE | AUTHENTICATION | NULL | GPL |
| CSV | ACTIVE | STORAGE ENGINE | NULL | GPL |
| MEMORY | ACTIVE | STORAGE ENGINE | NULL | GPL |
| InnoDB | ACTIVE | STORAGE ENGINE | NULL | GPL |
| BLACKHOLE | ACTIVE | STORAGE ENGINE | NULL | GPL |
| FEDERATED | DISABLED | STORAGE ENGINE | NULL | GPL |
| partition | ACTIVE | STORAGE ENGINE | NULL | GPL |
| ngram | ACTIVE | FTPARSER | NULL | GPL |
+----------------------------+----------+--------------------+---------+---------+
按照range分区的表是利用取值范围将数据分成分区,区间要连续并且不能互相重叠,使用values less than操作符进行分区定义
(root@localhost)[sj]CREATE TABLE emp_date (
-> id INT NOT NULL auto_increment,
-> name VARCHAR(255),
-> hiredate date not null default '1970-01-01',
-> key (id)
-> )
-> partition by range (year(hiredate)) (
-> partition p0 values less than(1995),
-> partition p1 values less than(2000),
-> partition p2 values less than(2005)
-> );
Query OK, 0 rows affected (0.02 sec)
在逻辑上emp_date 为一个表,在物理上存储在多个文件中:
[root@muze1 mysql_gtid]$ cd sj/
[root@muze1 sj]$ ll
total 460
-rwxrwxr-x 1 mysql mysql 61 Mar 26 21:02 db.opt
-rw-r----- 1 mysql mysql 8624 Jul 28 17:06 emp_date.frm
-rw-r----- 1 mysql mysql 114688 Jul 28 17:06 emp_date#P#p0.ibd
-rw-r----- 1 mysql mysql 114688 Jul 28 17:06 emp_date#P#p1.ibd
-rw-r----- 1 mysql mysql 114688 Jul 28 17:06 emp_date#P#p2.ibd
-rwxrwxr-x 1 mysql mysql 8584 Mar 26 21:03 t1.frm
-rwxrwxr-x 1 mysql mysql 98304 Mar 26 22:39 t1.ibd
[root@muze1 sj]$
emp_date.frm # 存储表原数据信息
emp_date#P#p0.ibd emp_date#P#p1.ibd emp_date#P#p2.ibd # Innodb数据文件
使用起来和不分区是一样的,看起来只有一个数据库,其实有多个分区文件,比如我们要插入一条数据,不需要指定分区,MySQL会自动帮我们处理。