云服务器内容精选

  • RANGE_N with * for start-date 输入: CREATE MULTISET TABLE Orders5 ( StoreNo SMALLINT, OrderNo INTEGER, OrderDate DATE, OrderTotal INTEGER ) PRIMARY INDEX(OrderNo) PARTITION BY RANGE_N ( OrderDate BETWEEN DATE * AND DATE '2016-12-31' EACH INTERVAL '1' YEAR, DATE '2017-01-01' EACH INTERVAL '1' MONTH, DATE '2020-01-01' AND DATE '2020-12-31' EACH INTERVAL '1' DAY ); 输出: CREATE TABLE Orders5 ( StoreNo SMALLINT, OrderNo INTEGER, OrderDate DATE, OrderTotal INTEGER ) DISTRIBUTE BY HASH (OrderNo) PARTITION BY RANGE (OrderDate) ( PARTITION Orders5_0 START (DATE '0001-01-01') END (DATE '2016-12-31') EVERY (INTERVAL '1' YEAR), PARTITION Orders5_1 START (DATE '2016-12-31') END (DATE '2020-01-01') EVERY (INTERVAL '1' MONTH), PARTITION Orders5_2 START (DATE '2020-01-01') END (DATE '2020-12-31') EVERY (INTERVAL '1' DAY) );
  • RANGE_N with * for end-date 输入: CREATE SET TABLE Orders4 ( StoreNo SMALLINT, OrderNo INTEGER, OrderDate DATE, OrderTotal INTEGER ) PRIMARY INDEX(OrderNo) PARTITION BY RANGE_N ( OrderDate BETWEEN DATE '2010-01-01' AND '2016-12-31' EACH INTERVAL '1' YEAR, DATE '2017-01-01' EACH INTERVAL '1' MONTH, DATE '2019-01-01' AND * ); 输出: CREATE TABLE Orders4 ( StoreNo SMALLINT, OrderNo INTEGER, OrderDate DATE, OrderTotal INTEGER ) DISTRIBUTE BY HASH (OrderNo) PARTITION BY RANGE (OrderDate) ( PARTITION Orders4_0 START (DATE '2010-01-01') END (DATE '2016-12-31') EVERY (INTERVAL '1' YEAR), PARTITION Orders4_1 START (DATE '2016-12-31') END (DATE '2020-01-01') EVERY (INTERVAL '1' MONTH) , PARTITION Orders4_2 START (DATE '2020-01-01') END (MAXVALUE) );
  • RANGE_N在字符串列的分区 输入: CREATE SET TABLE SC.TAB , NO FALLBACK, NO BEFORE JOURNAL, NO AFTER JOURNAL, CHECKSUM=DEFAULT, DEFAULT MERGEBLOCKRATIO ( ACCOUNT_NUM VARCHAR(255) CHARACTER SET LATIN NOT CASESPECIFIC NOT NULL ,ACCOUNT_MODIFIER_NUM CHAR(18) CHARACTER SET LATIN NOT CASESPECIFIC NOT NULL ,DATA_SOURCE_ID CHAR(10) CHARACTER SET LATIN NOT CASESPECIFIC ,END_DT DATE FORMAT 'YYYY-MM-DD' ,UPD_TXF_BATCHTD INTEGER COMPRESS ) PRIMARY INDEX XPKT0300_AGREEMENT (ACCOUNT_NUM,ACCOUNT_MODIFIER_NUM) PARTITION BY ( RANGE_N(DATA_SOURCE_ID BETWEEN 'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z' AND 'ZZ', NO RANGE ,UNKNOWN) ,CASE_N(END_DT IS NULL , NO CASE , UNKNOWN)) ; 输出: CREATE TABLE SC.TAB ( ACCOUNT_NUM VARCHAR( 255 ) /* CHARACTER SET LATIN*/ /* NOT CASESPECIFIC*/ NOT NULL ,ACCOUNT_MODIFIER_NUM CHAR( 18 ) /* CHARACTER SET LATIN*/ /* NOT CASESPECIFIC*/ NOT NULL ,DATA_SOURCE_ID CHAR( 10 ) /* CHARACTER SET LATIN*/ /* NOT CASESPECIFIC*/ ,END_DT DATE ,UPD_TXF_BATCHTD INTEGER /* COMPRESS */ ) DISTRIBUTE BY HASH ( ACCOUNT_NUM ,ACCOUNT_MODIFIER_NUM )/* PARTITION BY ( RANGE_N ( DATA_SOURCE_ID BETWEEN 'A' ,'B' ,'C' ,'D' ,'E' ,'F' ,'G' ,'H' ,'I' ,'J' ,'K' ,'L' ,'M' ,'N' ,'O' ,'P' ,'Q' ,'R' ,'S' ,'T' ,'U' ,'V' ,'W' ,'X' ,'Y' ,'Z' AND 'ZZ' ,NO RANGE ,UNKNOWN ) ,*/ /* CASE_N(END_DT IS NULL , NO CASE , UNKNOWN)) */ ;
  • RANGE_N with comma separated values 输入: CREATE TABLE orders10 (storeid INTEGER NOT NULL ,productid INTEGER NOT NULL ,orderdate DATE NOT NULL ,totalorders INTEGER NOT NULL) PRIMARY INDEX (storeid, productid) PARTITION BY ( RANGE_N(totalorders BETWEEN *, 100, 1000 AND *) ); 输出: CREATE TABLE orders10 (storeid INTEGER NOT NULL ,productid INTEGER NOT NULL ,orderdate DATE NOT NULL ,totalorders INTEGER NOT NULL) DISTRIBUTE BY HASH (storeid, productid) PARTITION BY RANGE (totalorders) ( PARTITION Orders10_0 END (100), PARTITION Orders10_1 END (1000), PARTITION Orders10_2 END (MAXVALUE) );
  • RANGE_N with different partition INTERVAL 输入: CREATE MULTISET TABLE tab1 ( TICD VARCHAR(10) , TCIT VARCHAR(10) , TCCM VARCHAR(50) , DW_Stat_Dt DATE ) PRIMARY INDEX ( TICD ) PARTITION BY RANGE_N ( DW_Stat_Dt BETWEEN DATE '0001-01-01' AND DATE '0001-01-04' EACH INTERVAL '1' DAY, DATE '0001-01-05' AND DATE '1899-12-31', DATE '1900-01-01' AND DATE '1900-01-01', DATE '1900-01-02' AND DATE '1999-12-31', DATE '2000-01-01' AND DATE '2009-12-31' EACH INTERVAL '1' YEAR, DATE '2010-01-01' AND DATE '2021-12-31' EACH INTERVAL '1' DAY, DATE '9999-12-31' AND DATE '9999-12-31', NO RANGE ); 输出: CREATE TABLE tab1 ( TICD VARCHAR( 10 ) , TCIT VARCHAR( 10 ) , TCCM VARCHAR( 50 ) , DW_Stat_Dt DATE ) DISTRIBUTE BY HASH (TICD) PARTITION BY RANGE (DW_Stat_Dt) ( PARTITION tab1_0 START (DATE '0001-01-01') END (DATE '0001-01-04') EVERY (INTERVAL '1' DAY), PARTITION tab1_1 START (DATE '0001-01-04') END (DATE '1899-12-31'), PARTITION tab1_2 START (DATE '1899-12-31') END (DATE '1900-01-01'), PARTITION tab1_ 3 START (DATE '1900-01-01') END (DATE '1999-12-31'), PARTITION tab1_4 START (DATE '1999-12-31') END (DATE '2009-12-31') EVERY (INTERVAL '1' YEAR) , PARTITION tab1_5 START (DATE '2009-12-31') END (DATE '2021-12-31') EVERY (INTERVAL '1' DAY) , PARTITION tab1_6 START (DATE '2021-12-31') END (DATE '9999-12-31') );
  • 通过DRS迁移MySQL分库分表总流程 本实践的主要任务流如图1所示: 图1 操作流程 表1 迁移流程 序号 步骤 说明 1 迁移前构造数据 迁移前在源端数据库构造数据,供迁移后查看是否迁移成功。 2 目标端DDM准备 创建VPC和安全组:为创建实例准备网络资源。 创建DDM实例:创建目标端DDM实例。 创建RDS for MySQ L实例 :创建DDM下关联的RDS for MySQL实例。 创建DDM账号:创建连接DDM逻辑库的账号。 创建逻辑库并关联RDS for MySQL实例:关联DDM与RDS for MySQL实例。 创建目标库表结构:在目标库创建表结构,供迁移数据使用。 3 迁移数据库 介绍创建DRS迁移任务和迁移的整体流程。 4 迁移后进行数据校验 通过DRS数据对比功能验证数据迁移结果。 父主题: MySQL分库分表迁移到DDM