首页 技术 正文
技术 2022年11月14日
0 收藏 419 点赞 3,515 浏览 1809 个字
一、分区1、分区概念
将某张表数据,分别存储到不同的区域中。
每个分区,都是独立的表,都要存储该分区的数据,索引信息。2、创建分区
创建表并指定分区的选项
create table 表名 (
定义...
)
Partition by 分区算法 (分区参数) 分区选项
(*分区所参与的字段必须为主键的一部分)3、分区算法
(1)、key 按照某个字段进行取余
create table test1 (
id int unsigned not null auto_increment,
title varchar(32) no null default '',
primary key (id)
)engine=myisam charset=utf8
partition by key (id) partitions 5;(2)、hash 按照某个表达式的值进行取余
--按照月份分成12个分区
create table test2 (
id int unsigned not null auto_increment,
birthday date,
primary key (id,birthday)
)engine=myisam charset=utf8
partition by hash (month(birthday)) partitions 12;
(*key,hash分区算法要求分区参数必须返回为整数)(3)、list 需要指定每个分区的存储条件
--按照四个季节分成4个分区
create table test3 (
id int unsigned not null auto_increment,
birthday date,
primary key (id,birthday)
)engine=myisam charset=utf8
partition by list (month(birthday)) (
partition p1 values in(3,4,5),
partition p2 values in(6,7,8),
partition p3 values in(9,10,11),
partition p4 values in(12,1,2)
);
(*list条件依赖的数据是列表形式)(4)、range 条件依赖的数据是一个条件表达式
--按年份分成70后,80后,90后,00后4个分区
create table test4 (
id int unsigned not null auto_increment,
birthday date,
primary key (id,birthday)
)engine=myisam charset=utf8
partition by range (year(birthday)) (
partition p70 values less than (1980),
partition p80 values less than (1990),
partition p90 values less than (2000),
partition p00 values less than MAXVALUE,
);4、查看mysql是否支持分区
> show variables like 'have_partitioning';
(*mysql5.6后移除了have_partitioning项,可以用SHOW PLUGINS;来查看)5、管理分区语法
(1)、key,hash
增加分区数量
> alter table test2 add partition partitions N;
减少分区数量
> alter table test2 coalesce partition N;
(*采用取余算法的分区数量的修改,不会导致已有分区数据的丢失)(2)、list,range
增加分区
> alter table test4 add partition (
partition p2010 values less than (2010)
);删除分区
> alter table test4 drop partition 分区名;
(*删除条件算法的分区,导致分区数据的丢失)6、选择分区算法
平均分配,就按照主键进行key即可
按照某种业务逻辑分区:
1、选择那种整数型
2、最容易被筛选的字段二、mysql服务器配置常用优化项支持的最大连接数
max_connections = 100
myisam配置
键缓冲的大小,建议不要超过物理内存的30%
key_buffer_size=55M
表缓存,缓存的是表文件的句柄
table_cache=256
innodb配置
innodb缓冲池的大小,最大可以为机器物理内存的80%
innodb_buffer_pool_size=107M
相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,031
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,520
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,368
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,148
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,781
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,862