MYCAT全局序列
Posted ph7seven
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了MYCAT全局序列相关的知识,希望对你有一定的参考价值。
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全局序列的主要内容,如果未能解决你的问题,请参考以下文章