Chinaunix首页 | 论坛 | 博客
  • 博客访问: 6683726
  • 博文数量: 1005
  • 博客积分: 8199
  • 博客等级: 中将
  • 技术积分: 13071
  • 用 户 组: 普通用户
  • 注册时间: 2010-05-25 20:19
个人简介

脚踏实地、勇往直前!

文章分类

全部博文(1005)

文章存档

2020年(2)

2019年(93)

2018年(208)

2017年(81)

2016年(49)

2015年(50)

2014年(170)

2013年(52)

2012年(177)

2011年(93)

2010年(30)

分类: Mysql/postgreSQL

2017-08-09 14:02:54


1.定义规则rule.xml

点击(此处)折叠或打开

  1. <tableRule name="auto-sharding-long-userid">
  2.         <rule>
  3.                 <columns>userid</columns>
  4.                 <algorithm>rang-long-userid</algorithm>
  5.         </rule>
  6. </tableRule>

  7. <function name="rang-long-userid"
  8.         class="io.mycat.route.function.AutoPartitionByLong">
  9.         <property name="mapFile">autopartition-long-userid.txt</property>
  10. </function>
[root@host01 conf]# more autopartition-long-userid.txt
# range start-end ,data node index
# K=1000,M=10000.
0-1000=0
1001-2000=1
2001-3000=2
3001-4000=3
4001-5000=4
5001-6000=5

2.schema.xml配置文件

点击(此处)折叠或打开

  1. <?xml version="1.0"?>
  2. <!DOCTYPE mycat:schema SYSTEM "schema.dtd">
  3. <mycat:schema xmlns:mycat="">

  4.         <schema name="logdb" checkSQLschema="false" sqlMaxLimit="100">
  5.           <table name="tb_log_t" primaryKey="ID" autoIncrement="true" dataNode="dn1,dn2,dn3,dn4,dn5,dn6" rule="mod-long" />
  6.           <table name="tb_user_t" dataNode="dn1,dn2,dn3,dn4,dn5,dn6" rule="sharding-by-intfile-provcode" />
  7.           <table name="tb_user_detail_t" dataNode="dn1,dn2,dn3,dn4,dn5,dn6" rule="auto-sharding-long-userid" />
  8.         </schema>
  9.         <schema name="coss03" checkSQLschema="false" sqlMaxLimit="100" dataNode="dnoss03"/>
  10.         <dataNode name="dn1" dataHost="localhost1" database="log01" />
  11.         <dataNode name="dn2" dataHost="localhost1" database="log02" />
  12.         <dataNode name="dn3" dataHost="localhost1" database="log03" />
  13.         <dataNode name="dn4" dataHost="localhost1" database="log04" />
  14.         <dataNode name="dn5" dataHost="localhost1" database="log05" />
  15.         <dataNode name="dn6" dataHost="localhost1" database="log06" />
  16.         <dataNode name="dnoss03" dataHost="localhost1" database="oss03" />
  17.         <dataHost name="localhost1" maxCon="1000" minCon="10" balance="0"
  18.                           writeType="0" dbType="mysql" dbDriver="native" switchType="1" slaveThreshold="100">
  19.                 <heartbeat>select user()</heartbeat>
  20.                 <!-- can have multi write hosts -->
  21.                 <writeHost host="hostM1" url="192.168.56.141:3306" user="root"
  22.                                    password="mysql">
  23.                         <!-- can have multi read hosts -->
  24.                         <readHost host="hostS2" url="192.168.56.142:3306" user="root" password="mysql" />
  25.                 </writeHost>
  26.         </dataHost>
  27. </mycat:schema>

3.建表语句
CREATE TABLE tb_user_detail_t (
  userid bigint not null primary key,
  name varchar(64) DEFAULT NULL,
  createtime datetime DEFAULT CURRENT_TIMESTAMP,
  moditytime datetime DEFAULT CURRENT_TIMESTAMP
) ENGINE=InnoDB DEFAULT CHARSET=utf8;


写入数据
insert into tb_user_detail_t(userid,name) values(999,'name999');
insert into tb_user_detail_t(userid,name) values(1999,'name999');
insert into tb_user_detail_t(userid,name) values(2999,'name999');
insert into tb_user_detail_t(userid,name) values(3999,'name999');
insert into tb_user_detail_t(userid,name) values(4999,'name999');
insert into tb_user_detail_t(userid,name) values(5999,'name999');


-- The End --

阅读(2906) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~