Chinaunix首页 | 论坛 | 认证专区 | 博客 登录 | 注册

东南西北风andyhuang.blog.chinaunix.net

脚踏实地,一步一个脚印!

  • 博客访问: 2669121
  • 博文数量: 688
  • 博客积分: 8199
  • 博客等级: 中将
  • 技术积分: 9599
  • 用 户 组: 普通用户
  • 注册时间: 2010-05-25 20:19
个人简介

脚踏实地、勇往直前!

文章分类

全部博文(688)

文章存档

2017年(67)

2016年(48)

2015年(50)

2014年(169)

2013年(52)

2012年(177)

2011年(93)

2010年(30)

微信关注

IT168企业级官微



微信号:IT168qiye



系统架构师大会



微信号:SACC2013

订阅
热词专题
mycat分库规则crc32slot 2017-08-10 09:57:11

分类: Mysql/postgreSQL


crs32算法,分库字段类型支撑int和varchar.

1.rule.xml

点击(此处)折叠或打开

  1. <tableRule name="crc32slot">
  2.          <rule>
  3.                  <columns>id</columns>
  4.                  <algorithm>crc32slot</algorithm>
  5.          </rule>
  6.  </tableRule>
  7.  <function name="crc32slot"
  8.                    class="io.mycat.route.function.PartitionByCRC32PreSlot">
  9.          <property name="count">6</property><!-- 要分片的数据库节点数量,必须指定,否则没法分片 -->
  10.  </function>
count=6指定需要分库的个数.

2.schema.xml

点击(此处)折叠或打开

  1. <?xml version="1.0"?>
  2. <!DOCTYPE mycat:schema SYSTEM "schema.dtd">
  3. <mycat:schema xmlns:mycat="http://io.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.           <table name="tb_user_murmur_t" dataNode="dn1,dn2,dn3,dn4,dn5,dn6" rule="sharding-by-murmur" />
  9.           <table name="tb_user_murmur_string_t" dataNode="dn1,dn2,dn3,dn4,dn5,dn6" rule="sharding-by-murmur-userid" />
  10.           <table name="tb_user_crc32slot_t" dataNode="dn1,dn2,dn3,dn4,dn5,dn6" rule="crc32slot" />
  11.         </schema>
  12.         <schema name="coss03" checkSQLschema="false" sqlMaxLimit="100" dataNode="dnoss03"/>
  13.         <dataNode name="dn1" dataHost="localhost1" database="log01" />
  14.         <dataNode name="dn2" dataHost="localhost1" database="log02" />
  15.         <dataNode name="dn3" dataHost="localhost1" database="log03" />
  16.         <dataNode name="dn4" dataHost="localhost1" database="log04" />
  17.         <dataNode name="dn5" dataHost="localhost1" database="log05" />
  18.         <dataNode name="dn6" dataHost="localhost1" database="log06" />
  19.         <dataNode name="dnoss03" dataHost="localhost1" database="oss03" />
  20.         <dataHost name="localhost1" maxCon="1000" minCon="10" balance="0"
  21.                           writeType="0" dbType="mysql" dbDriver="native" switchType="1" slaveThreshold="100">
  22.                 <heartbeat>select user()</heartbeat>
  23.                 <!-- can have multi write hosts -->
  24.                 <writeHost host="hostM1" url="192.168.56.141:3306" user="root"
  25.                                    password="mysql">
  26.                         <!-- can have multi read hosts -->
  27.                         <readHost host="hostS2" url="192.168.56.142:3306" user="root" password="mysql" />
  28.                 </writeHost>
  29.         </dataHost>
  30. </mycat:schema>

3.创建表
CREATE TABLE `tb_user_crc32slot_t` (
  `id` varchar(32) NOT NULL,
  `name` varchar(64) DEFAULT NULL,
  `createtime` datetime DEFAULT CURRENT_TIMESTAMP,
  `moditytime` datetime DEFAULT CURRENT_TIMESTAMP
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

写入数据:
insert into tb_user_crc32slot_t(id,name) values('a0002','name1');
insert into tb_user_crc32slot_t(id,name) values('a0003','name1');
insert into tb_user_crc32slot_t(id,name) values('a0004','name1');
insert into tb_user_crc32slot_t(id,name) values('a0005','name1');
insert into tb_user_crc32slot_t(id,name) values('a0006','name1');
insert into tb_user_crc32slot_t(id,name) values('a0007','name1');
insert into tb_user_crc32slot_t(id,name) values('a0008','name1');
insert into tb_user_crc32slot_t(id,name) values('a0009','name1');
insert into tb_user_crc32slot_t(id,name) values('a0010','name1');
insert into tb_user_crc32slot_t(id,name) values('a0011','name1');
insert into tb_user_crc32slot_t(id,name) values('a0012','name1');
insert into tb_user_crc32slot_t(id,name) values('a0013','name1');
insert into tb_user_crc32slot_t(id,name) values('a0014','name1');
insert into tb_user_crc32slot_t(id,name) values('a0015','name1');

-- The End --
阅读(715) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~
评论热议
请登录后评论。

登录 注册