码迷,mamicode.com
首页 > 其他好文 > 详细

MYCAT全局序列

时间:2018-10-28 16:50:25      阅读:181      评论:0      收藏:0      [点我收藏+]

标签:业务   span   mycat   str   one   and   false   enum   his   

1、本地文件方式

sequnceHandlerType = 0

  /root/data/program/mycat/conf/server.xml   <property name="sequnceHandlerType">0</property>

 

配置sequence_conf.properties

  /root/data/program/mycat/conf/sequence_conf.properties  

  USERS.HISIDS=
  USERS.MINID=1001
  USERS.MAXID=100000000
  USERS.CURID=1000

  说明:这里的USERS是server.xml中配置的table name的大写,千万千万注意

<schema name="db_user" checkSQLschema="false" sqlMaxLimit="100">
        <table name="data_dictionary" type="global" dataNode="db_user_dataNode1,db_user_dataNode2" primaryKey="dataDictionaryID"/>
        <table name="users" dataNode="db_user_dataNode$1-2"  rule="mod-userID-long" primaryKey="userID">
            <childTable name="user_address"  joinKey="userID" parentKey="userID" primaryKey="addressID"/>
        </table>
</schema>

使用next value for MYCATSEQ_XXX

  INSERT INTO users(userID,phoneNum) values(next value for MYCATSEQ_USERS,‘13612345678‘);

效果

技术分享图片

2、数据库方式

sequnceHandlerType = 1

  /root/data/program/mycat/conf/server.xml   <property name="sequnceHandlerType">1</property>

 

配置/root/data/program/mycat/conf/sequence_db_conf.properties

  USERS=db_user_dataNode2

在指定的schema中加入mycat_sequence表
  <table name = "mycat_sequence" dataNode ="db_user_dataNode2" />

<schema name="db_user" checkSQLschema="false" sqlMaxLimit="100">
        <table name="data_dictionary" type="global" dataNode="db_user_dataNode1,db_user_dataNode2" primaryKey="dataDictionaryID"/>
        <table name="users" dataNode="db_user_dataNode$1-2"  rule="mod-userID-long" primaryKey="userID">
            <childTable name="user_address"  joinKey="userID" parentKey="userID" primaryKey="addressID"/>
        </table>

        <table name = "mycat_sequence" dataNode ="db_user_dataNode2" />
    </schema>

 

使用next value for MYCATSEQ_XXX或者指定autoIncrement

 insert into users(userID,phoneNum)values(next value for MYCATSEQ_USERS,‘2222222‘);

技术分享图片

 

另一种方式:指定 autoIncrement="true"

<schema name="db_user" checkSQLschema="false" sqlMaxLimit="100">
        <table name="data_dictionary" type="global" dataNode="db_user_dataNode1,db_user_dataNode2" primaryKey="dataDictionaryID"/>
        <table name="users" dataNode="db_user_dataNode$1-2"  rule="mod-userID-long" primaryKey="userID" autoIncrement="true">
            <childTable name="user_address"  joinKey="userID" parentKey="userID" primaryKey="addressID"/>
        </table>

        <table name = "mycat_sequence" dataNode ="db_user_dataNode2" />
    </schema>

insert into users(phoneNum)values("8888");

技术分享图片

3、本地时间戳方式

ID= 64 位二进制 (42(毫秒)+5(机器 ID)+5(业务编码)+12(重复累加)

sequnceHandlerType = 2

  /root/data/program/mycat/conf/server.xml   <property name="sequnceHandlerType">2</property>

 

配置sequence_time_conf.properties

  默认配置即可

 

指定autoIncrement

  只能指定autoIncrement

<schema name="db_user" checkSQLschema="false" sqlMaxLimit="100">
        <table name="data_dictionary" type="global" dataNode="db_user_dataNode1,db_user_dataNode2" primaryKey="dataDictionaryID"/>
        <table name="users" dataNode="db_user_dataNode$1-2"  rule="mod-userID-long" primaryKey="userID" autoIncrement="true">
            <childTable name="user_address"  joinKey="userID" parentKey="userID" primaryKey="addressID"/>
        </table>

        <table name = "mycat_sequence" dataNode ="db_user_dataNode2" />
    </schema>

技术分享图片

MYCAT全局序列

标签:业务   span   mycat   str   one   and   false   enum   his   

原文地址:https://www.cnblogs.com/ph7seven/p/9865990.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!