设置分片规则的DDL语句 DRDS支持直接连接dbproxy执行DDL语句,本文为您介绍设置分片规则的DDL语句。 注意 仅V5.1.20.0.13及以后版本的实例,支持使用本文介绍的DDL语句。 设置分片规则 各种表类型的分片规则DDL语法,如下表所示: 表类型 语法 示例 分片表 sharding @@table name'' set type'sharding' and shardingalgo'' and shardingid'' [ and algoparameter'algovalue']… [and dn'']; sharding @@table name'employee' set type'sharding' and shardingalgo'PartitionByEnumAndStringMod' and mapfile'{"BJ":"0","SH":"1"}' and defaultnode'2' and shardingid'employeeid' and shardingarea'areaid' and dn'drdstest1,drdstest2,drdstest3'; 分片表+库内分表 sharding @@table name'' set type'inner' and shardingalgo'' and shardingid'' [ and algoparameter'algovalue']… and innershardingalgo'' and innershardingid'' [ and inneralgoparameter'algovalue']… and innertotal'' [and dn'']; sharding @@table name’employee’ set type'inner' and shardingalgo'PartitionByFileMap' and mapfile'{"1":"0","2":"1"}' and defaultnode'0' and shardingid'employeeid' and innershardingalgo'PartitionByDateRange' and innershardingid'areaid' and innerstartdate'20180710' and innertimeunitlen'1' and innertimeunittype'year' and innertotal'2' and dn'drdstest1,drdstest2'; 分桶表 sharding @@table name'' set type'sharding' and shardingalgo'' and shardingid'' [ and algoparameter'algovalue']… and buckets’’ [and dn'']; sharding @@table name'bucket' set type'sharding' and shardingalgo'PartitionByFileMap' and mapfile'{"1":"0","2":"1","3":"2"}' and defaultnode'0' and shardingid'employeeid' and buckets'2'; 单片表+库内分表 sharding @@table name'' set type' inner ' and innershardingalgo'' and shardingid'' [ and inneralgoparameter'algovalue']… and innertotal'' and dn''; sharding @@table name'singleinner' set type'inner' and innershardingalgo'PartitionByMod' and innershardingid'employeeid' and innertotal'2' and dn'drdstest1'; 单片表 sharding @@table name'' set type' single ' and dn''; sharding @@table name'single' set type'single' and dn'drdstest1'; 全局表 sharding @@table name'' set type'global' [and dn'']; sharding @@table name'global' set type'global';