8.1 时间戳方式全局序列的配置

配置表tb的id列为时间戳方式全局序列,并按id列分片

1)cluster.conf

sequenceHandlerType=2
sequenceStartTime=2010-10-01 09:42:54
...

2)bootstrap.conf

instanceId=1
...

3)user.xml

<?xml version="1.0" encoding="UTF-8"?>
<dble:user xmlns:dble="http://dble.cloud/">
    <managerUser name="test" password="test"/>
    <shardingUser name="abc" password="abc" schemas="myschema" maxCon="1000000">
    </shardingUser>

</dble:user>

4)db.xml

<?xml version="1.0"?>
<dble:db xmlns:dble="http://dble.cloud/" >
    <dbGroup name="host_1" rwSplitMode="0" delayThreshold="10000">
        <heartbeat >select USER()</heartbeat>
        <dbInstance name="hostM1" url="172.100.10.101:3306" user="test1" password="test1" maxCon="1000" minCon="1000" primary="true" />
    </dbGroup>
    <dbGroup name="host_2" rwSplitMode="0" delayThreshold="10000">
        <heartbeat >select USER()</heartbeat>
        <dbInstance name="hostM2" url="172.100.10.102:3306" user="test1" password="test1" maxCon="1000" minCon="1000" primary="true" />
    </dbGroup>
</dble:db>

5)sharding.xml

<?xml version="1.0"?>
<dble:sharding xmlns:dble="http://dble.cloud/">
    <schema name="myschema" shardingNode="dn1">
    <shardingTable name="sbtest1"  shardingNode="dn1,dn2" function="mod" shardingColumn="id" incrementColumn="id" />
    </schema> 
    <shardingNode name="dn1" dbGroup="host_1" database="dble"/>
    <shardingNode name="dn2" dbGroup="host_2" database="dble"/>
    <function name="mod" class="Hash">
                <property name="partitionCount">2</property>
                <property name="partitionLength">1</property>
        </function>
</dble:sharding>

6 )实验

```mysql mysql -utest -p111111 -h127.0.0.1 -P8066 -Dmyschema mysql> drop table if exists sbtest1; Query OK, 0 rows affected (0.05 sec) mysql> create table sbtest1(id bigint(20), k int unsigned not null default '0', primary key(id)); Query OK, 0 rows affected (0.05 sec)

mysql> insert into sbtest1 values(2); Query OK, 1 row affected (0.11 sec)

mysql> select * from sbtest1; 查看序列

注意事项,自增列的数据类型要是bigint

results matching ""

    No results matching ""