MySQL命令
MySQL表分区相关命令
```sql -- 创建范围分区 create table `表名`( `xxx` xxx not null, .... ) partition by range(xxx)( partition 分区名1 values less than (范围) data directory = "/xxx/xxx/xxx", partition 分区名2 values less than (范围) data directory = "/xxx/xxx/xxx", ...... ); -- 创建枚举分区 create table `表名`( `xxx` xxx not null, .... ) partition by list(xxx)( partition 分区名1 values in (枚举值1,枚举值2...), partition 分区名2 values in (枚举值), ...... ); -- 创建常规哈希分区 create table `表名`( `xxx` xxx not null, .... ) partition by hash(xxx) partitions 分区数量; -- 创建线性哈希分区 create table `表名`( `xxx` xxx not null, .... ) partition by linear hash(xxx) partitions 分区数量; -- 创建Key键分区 create table `表名`( `xxx` xxx not null, .... ) partition by key(xxx) partitions 分区数量; -- 创建Sub子分区 create table `表名`( `xxx` xxx not null, .... ) partition by range(父分区键) subpartition by hash(子分区键)( partition 分区名1 values less than (范围1)( subpartition 子分区名1, subpartition 子分区名2, ...... ), partition 分区名2 values less than (范围2)( subpartition 子分区名1, subpartition 子分区名2, ...... ), ...... ); -- 查询一张表各个分区的数据量 select partition_name as "分区名称",table_rows as "数据行数" from information_schema.partitions where table_name = '表名'; -- 查询一张表父子分区的数据量 select partition_name as "父分区名称", subpartition_name as "子分区名称", table_rows as "子分区行数" from information_schema.partitions where table_name = '表名'; -- 查询MySQL中所有表分区的信息 select * from information_schema.partitions; -- 查询一张表某个分区中的所有数据 select * from 表名 partition (分区名); -- 对于一张已存在的表添加分区 alter table 表名 reorganize partition 分区名 into ( partition 分区名1 values less than (范围) data directory = "/xxx/xxx/xxx", partition 分区名2 values less than (范围) data directory = "/xxx/xxx/xxx", ...... ); -- 将多个分区合并成一个分区 alter table 表明 reorganize partition 分区名1,分区名2... into ( partition 新分区名 values less than (范围) ); -- 清空一个分区中的所有数据 alter table 表名 truncate partition 分区名; -- 删除一个表的指定分区 alter table 表名 drop partition 分区名; -- 重建一张表的分区 alter table 表名 rebuild partition 分区名; -- 分析一个表分区 alter table 表名 analyze partition 分区名; -- 优化一个表分区 alter table 表名 optimize partition 分区名; -- 检查一个表分区 alter table 表名 check partition 分区名; -- 修复一个表分区 alter table 表名 repair partition 分区名; -- 减少hash、key分区方式的 n 个分区 alter table 表名 coalesce partition n; -- 将一张表的分区切换到另一张表 alter table 表名1 exchange partition 分区名 with table 表名2; -- 移除一张表的所有分区 alter table 表名 remove partitioning; ```
顶部
收展
底部
[TOC]
目录
MySQL基础操作命令
MySQL 库相关命令
MySQL 表相关命令
MySQL 表分析检查与修复
MySQL 增删改查语句
MySQL 数据库函数
MySQL 索引相关命令
MySQL 事务与锁相关的命令
MySQL 存储过程、存储函数与触发器
MySQL用户与权限管理
MySQL视图与临时表
MySQL导出导入与备份还原
MySQL表分区相关命令
MySQL系统变量
相关推荐
MySQL教程
MySQL索引
MySQL事务
MySQL锁机制
MySQL版本特性