-
示意图
[外链图片转存失败(img-KwEgQ1Yi-1568967951575)(http://yum.sieracpack.com:91/mycat.jpg)]
-
mycat规则制定
schema.xml
<?xml version="1.0"?> <!DOCTYPE mycat:schema SYSTEM "schema.dtd"> <mycat:schema xmlns:mycat="http://io.mycat/"> <schema name="logicdb" checkSQLschema="false" > <!-- 制定分片规则 --> <table primaryKey="id" name="code_data" dataNode="dn1,dn2,dn3,dn4,dn5" rule="sharding-by-date" /> <!-- type=global:定义全局表,用于不变化或少量变化的的表数据,所有分库都一致--> <table primaryKey="id" type="global" dataNode="dn1,dn2,dn3,dn4,dn5" name="code_data_batch_report" /> <table primaryKey="id" type="global" dataNode="dn1,dn2,dn3,dn4,dn5" name="code_data_import_error" /> <table primaryKey="id" type="global" dataNode="dn1,dn2,dn3,dn4,dn5" name="code_data_upload_moa" /> <table primaryKey="id" type="global" dataNode="dn1,dn2,dn3,dn4,dn5" name="code_data_upload_moa_record" /> <table primaryKey="id" type="global" dataNode="dn1,dn2,dn3,dn4,dn5" name="code_data_upload_record" /> <table primaryKey="id" type="global" dataNode="dn1,dn2,dn3,dn4,dn5" name="create_code_bag" /> <table primaryKey="id" type="global" dataNode="dn1,dn2,dn3,dn4,dn5" name="create_code_base" /> <table primaryKey="id" type="global" dataNode="dn1,dn2,dn3,dn4,dn5" name="distributor" /> <table primaryKey="id" type="global" dataNode="dn1,dn2,dn3,dn4,dn5" name="error_moa_code_data" /> <table primaryKey="id" type="global" dataNode="dn1,dn2,dn3,dn4,dn5" name="factory" /> <table primaryKey="id" type="global" dataNode="dn1,dn2,dn3,dn4,dn5" name="product" /> <table primaryKey="id" type="global" dataNode="dn1,dn2,dn3,dn4,dn5" name="production_task" /> <table primaryKey="id" type="global" dataNode="dn1,dn2,dn3,dn4,dn5" name="query_report" /> <table primaryKey="id" type="global" dataNode="dn1,dn2,dn3,dn4,dn5" name="query_report_detail" /> <table primaryKey="id" type="global" dataNode="dn1,dn2,dn3,dn4,dn5" name="query_report_security" /> <table primaryKey="id" type="global" dataNode="dn1,dn2,dn3,dn4,dn5" name="query_report_security_detail" /> <table primaryKey="id" type="global" dataNode="dn1,dn2,dn3,dn4,dn5" name="rdc_user" /> <table primaryKey="id" type="global" dataNode="dn1,dn2,dn3,dn4,dn5" name="rdc_warehouse" /> <table primaryKey="id" type="global" dataNode="dn1,dn2,dn3,dn4,dn5" name="storage_data" /> <table primaryKey="id" type="global" dataNode="dn1,dn2,dn3,dn4,dn5" name="storage_data_error" /> <table primaryKey="id" type="global" dataNode="dn1,dn2,dn3,dn4,dn5" name="storage_data_upload_record" /> <table primaryKey="id" type="global" dataNode="dn1,dn2,dn3,dn4,dn5" name="sys_dict" /> <table primaryKey="id" type="global" dataNode="dn1,dn2,dn3,dn4,dn5" name="sys_param" /> <table primaryKey="id" type="global" dataNode="dn1,dn2,dn3,dn4,dn5" name="sys_user" /> </schema> <dataNode name="dn1" dataHost="host" database="tom1" /> <dataNode name="dn2" dataHost="host" database="tom2" /> <dataNode name="dn3" dataHost="host" database="tom3" /> <dataNode name="dn4" dataHost="host" database="tom4" /> <dataNode name="dn5" dataHost="host" database="tom5" /> <dataHost name="host" maxCon="1000" minCon="10" balance="0" writeType="0" dbType="mysql" dbDriver="native"> <heartbeat>select 1</heartbeat> <writeHost host="hostM1" url="192.168.1.226:3308" user="root" password="sierac1q2w3e" /> </dataHost> </mycat:schema>
server.xml
<!-- db user --> <user name="root"> <property name="password">sierac1q2w3e</property> <!-- 逻辑库,与schema.xml中name对应 --> <property name="schemas">logicdb</property> </user>
rule.xml
<!-- 按照日期分片,与schema.xml中逻辑表code_data的rule对应 --> <tableRule name="sharding-by-date"> <rule> <columns>create_date</columns> <algorithm>sharding-by-date</algorithm> </rule> </tableRule> <!-- 对应的分片函数,开始日期代表从哪天开始循环写入--> <function name="sharding-by-date" class="io.mycat.route.function.PartitionByDate"> <property name="dateFormat">yyyy-MM-dd</property> <property name="sBeginDate">2018-01-03</property> <!-- 如果配置了 sEndDate 则代表数据达到了这个日期的分片后,循环从开始分片插入,分片可以理解为整个规则db1-dbn --> <property name="sEndDate">2018-01-07</property> <!-- 1天一个分区,一个分区可以理解为一个db schema--> <property name="sPartionDay">1</property> </function>
mycat分库
猜你喜欢
转载自blog.csdn.net/fzt12138/article/details/101065091
今日推荐
周排行