Windows环境Mycat数据库分库分表中间件部署

2023-11-02

2016-08-23 00:17  957人阅读  评论(0)  收藏  举报
  分类:

版权声明:本文为博主原创文章,未经博主允许不得转载。

目录(?)[+]

下载地址MYCAT官方网站

jdk安装配置

  1. 首先去oracle官网下载并安装jdk8,添加环境变量,JAVA_HOME设置为D:\Worksoftware\Java\jdk1.8
  2. CLASSPATH设置为.;%JAVA_HOME%\lib;%JAVA_HOME%\lib\tools.jar
  3. path系统变量追加%JAVA_HOME%\bin;

Mycat安装配置

  1. 首先添加Windows环境变量,MYCAT_HOME设置为安装目录E:\WorkSoftWare\MycatServer1.5

  2. 为了降低资源占用,mycat的jvm设置在startup_nowrap.bat,打开后可以清楚看到如下配置: 
    “%JAVA_CMD%” -server -Xms1G -Xmx2G -XX:MaxPermSize=64M -XX:+AggressiveOpts -XX:MaxDirectMemorySize=1G -DMYCAT_HOME=%MYCAT_HOME% -cp “..\conf;..\lib*” io.mycat.MycatStartup 
    这里将-Xms1G改成-Xms512M,-Xmx2G改成-Xmx1024M,保存后重新启动即可.

  3. wrapper.conf文件里的改成wrapper.java.command=E:\WorkSoftWare\jdk1.8\bin\java.exe

Mycat启动的配置

schema.xml配置文件,如果分库在不同的服务器,可以配置两个datahost;如果在一个datahost中配置多个writeHost,则为主从配置。type=”global”时,为全局表

?xml version="1.0"?> <!DOCTYPE mycat:schema SYSTEM "schema.dtd"> <mycat:schema xmlns:mycat="http://org.opencloudb/" > <!--在这一行参数里面,schema name定义了可以在MyCAT前端显示的逻辑数据库的名字,checkSQLschema这个参数为False的时候,表明MyCAT会自动忽略掉表名前的数据库名,比如说mydatabase1.test1,会被当做test1;sqlMaxLimit指定了SQL语句返回的行数限制--> <schema name="TESTDB" checkSQLschema="false" sqlMaxLimit="100"> <!-- 主键范围规则 --> <!-- 这一行代表在MyCAT前端会显示哪些表名,类似几行都代表一样的意思,这里强调的是表,而MyCAT并不会在配置文件里面定义表结构,如果在前端使用show create table ,MyCAT会显示正常的表结构信息,观察Debug日志,可以看到,MyCAT把命令分发给了dn1代表的数据库,然后把dn1的查询结果返回给了前端 可以判断,类似的数据库级别的一些查询指令,有可能是单独分发给某个节点,然后再把某个节点的信息返回给前端。 dataNode的意义很简单,这个逻辑表的数据存储在后端的哪几个数据库里面rule代表的是这个逻辑表students的具体切分策略,目前MyCAT只支持按照某一个特殊列,遵循一些特殊的规则来切分,如取模,枚举等,具体的留给之后细说 --> <table name="travelrecord" dataNode="dn1,dn2,dn3" rule="auto-sharding-long" /> <table name="company" primaryKey="ID" dataNode="dn3,dn2,dn1" rule="mod-long"/> <table name="goods" primaryKey="ID" type="global" dataNode="dn1,dn2" /> <!--求模分片随机规则 --> <table name="hotnews" primaryKey="ID" dataNode="dn1,dn2,dn3" rule="mod-long" /> <table name="employee" primaryKey="ID" dataNode="dn1,dn2" rule="sharding-by-intfile" /> <table name="customer" primaryKey="ID" dataNode="dn1,dn2" rule="sharding-by-intfile"> <!-- childtable我在测试中并没有实际用起来不过在MyCAT的设计文档里面有提到,childtable是一种依赖于父表的结构, 这意味着,childtable的joinkey会按照父表的parentKey的策略一起切分,当父表与子表进行连接, 且连接条件是childtable.joinKey=parenttable.parentKey时,不会进行跨库的连接. --> <childTable name="orders" primaryKey="ID" joinKey="customer_id" parentKey="id"> <childTable name="order_items" joinKey="order_id" parentKey="id" /> </childTable> <childTable name="customer_addr" primaryKey="ID" joinKey="customer_id" parentKey="id" /> </table> <!-- 全局表是自动克隆到所有定义的数据节点,这样可以与拆分节点的任何表连接查询,是在同一个数据节点--> <table name="news_table" primaryKey="ID" type="global" dataNode="dn1,dn2,dn3" /> </schema> <dataNode name="dn1" dataHost="localhost1" database="mycatDB1" /> <dataNode name="dn2" dataHost="localhost1" database="mycatDB2" /> <dataNode name="dn3" dataHost="localhost1" database="mycatDB3" /> <!-- dataHost配置的是实际的后端数据库集群,大部分参数简单易懂,这里就不一个个介绍了,只介绍比较重要的两个参数,writeType和balance. --> <!-- writeType和balance是用来控制后端集群的读写分离的关键参数,这里我用了双主双从的集群配置 这里的测试过程比较麻烦,所以直接贴结论: 1.balance=0时,读操作都在localhost上(localhost失败时,后端直接失败) 2.balance=1时,读操作会随机分散在localhost1和两个readhost上面(localhost失败时,写操作会在localhost1,如果localhost1再失败,则无法进行写操作) 3.balance=2时,写操作会在localhost上,读操作会随机分散在localhost1,localhost1和两个readhost上面(同上) 4.writeType=0时,写操作会在localhost上,如果localhost失败,会自动切换到localhost1,localhost恢复以后并不会切换回localhost进行写操作 5.writeType=1时,写操作会随机分布在localhost和localhost1上,单点失败并不会影响集群的写操作,但是后端的从库会无法从挂掉的主库获取更新,会在读数据的时候出现数据不一致 举例:localhost失败了,写操作会在localhost1上面进行,localhost1的主从正常运行,但是localhost的从库无法从localhost获取更新,localhost的从库于其他库出现数据不一致 --> <dataHost name="localhost1" maxCon="1000" minCon="10" balance="0" writeType="0" dbType="mysql" dbDriver="native" switchType="1" slaveThreshold="100"> <heartbeat> select user() </heartbeat> <!-- can have multi write hosts --> <writeHost host="hostM1" url="localhost:3306" user="root" password="123456"> <!-- can have multi read hosts --> <!--<readHost host="hostS2" url="192.168.1.200:3306" user="root" password="xxx" />--> </writeHost> </dataHost> </mycat:schema>
<span class="hljs-pi" style="color: rgb(0, 102, 102); box-sizing: border-box; font-family: 'Source Code Pro', monospace; font-size: 14px; line-height: 20.2999992370605px; white-space: pre; background-color: rgba(128, 128, 128, 0.0470588);"><?xml version="1.0"?></span><span style="color: rgb(51, 51, 51); font-family: 'Source Code Pro', monospace; font-size: 14px; line-height: 20.2999992370605px; white-space: pre; background-color: rgba(128, 128, 128, 0.0470588);"></span><span class="hljs-doctype" style="color: rgb(102, 0, 102); box-sizing: border-box; font-family: 'Source Code Pro', monospace; font-size: 14px; line-height: 20.2999992370605px; white-space: pre; background-color: rgba(128, 128, 128, 0.0470588);"><!DOCTYPE mycat:schema SYSTEM "schema.dtd"></span><span style="color: rgb(51, 51, 51); font-family: 'Source Code Pro', monospace; font-size: 14px; line-height: 20.2999992370605px; white-space: pre; background-color: rgba(128, 128, 128, 0.0470588);"></span><span class="hljs-tag" style="color: rgb(0, 102, 102); box-sizing: border-box; font-family: 'Source Code Pro', monospace; font-size: 14px; line-height: 20.2999992370605px; white-space: pre; background-color: rgba(128, 128, 128, 0.0470588);"><<span class="hljs-title" style="box-sizing: border-box; color: rgb(0, 0, 136);">mycat:schema</span> <span class="hljs-attribute" style="box-sizing: border-box; color: rgb(102, 0, 102);">xmlns:mycat</span>=<span class="hljs-value" style="box-sizing: border-box; color: rgb(0, 136, 0);">"http://org.opencloudb/"</span> ></span><span style="color: rgb(51, 51, 51); font-family: 'Source Code Pro', monospace; font-size: 14px; line-height: 20.2999992370605px; white-space: pre; background-color: rgba(128, 128, 128, 0.0470588);"></span><span class="hljs-comment" style="color: rgb(136, 0, 0); box-sizing: border-box; font-family: 'Source Code Pro', monospace; font-size: 14px; line-height: 20.2999992370605px; white-space: pre; background-color: rgba(128, 128, 128, 0.0470588);"><!--在这一行参数里面,schema name定义了可以在MyCAT前端显示的逻辑数据库的名字,checkSQLschema这个参数为False的时候,表明MyCAT会自动忽略掉表名前的数据库名,比如说mydatabase1.test1,会被当做test1;sqlMaxLimit指定了SQL语句返回的行数限制--></span><span style="color: rgb(51, 51, 51); font-family: 'Source Code Pro', monospace; font-size: 14px; line-height: 20.2999992370605px; white-space: pre; background-color: rgba(128, 128, 128, 0.0470588);">    </span><span class="hljs-tag" style="color: rgb(0, 102, 102); box-sizing: border-box; font-family: 'Source Code Pro', monospace; font-size: 14px; line-height: 20.2999992370605px; white-space: pre; background-color: rgba(128, 128, 128, 0.0470588);"><<span class="hljs-title" style="box-sizing: border-box; color: rgb(0, 0, 136);">schema</span> <span class="hljs-attribute" style="box-sizing: border-box; color: rgb(102, 0, 102);">name</span>=<span class="hljs-value" style="box-sizing: border-box; color: rgb(0, 136, 0);">"TESTDB"</span> <span class="hljs-attribute" style="box-sizing: border-box; color: rgb(102, 0, 102);">checkSQLschema</span>=<span class="hljs-value" style="box-sizing: border-box; color: rgb(0, 136, 0);">"false"</span> <span class="hljs-attribute" style="box-sizing: border-box; color: rgb(102, 0, 102);">sqlMaxLimit</span>=<span class="hljs-value" style="box-sizing: border-box; color: rgb(0, 136, 0);">"100"</span>></span><span style="color: rgb(51, 51, 51); font-family: 'Source Code Pro', monospace; font-size: 14px; line-height: 20.2999992370605px; white-space: pre; background-color: rgba(128, 128, 128, 0.0470588);">        </span><span class="hljs-comment" style="color: rgb(136, 0, 0); box-sizing: border-box; font-family: 'Source Code Pro', monospace; font-size: 14px; line-height: 20.2999992370605px; white-space: pre; background-color: rgba(128, 128, 128, 0.0470588);"><!-- 主键范围规则 --></span><span style="color: rgb(51, 51, 51); font-family: 'Source Code Pro', monospace; font-size: 14px; line-height: 20.2999992370605px; white-space: pre; background-color: rgba(128, 128, 128, 0.0470588);">        </span><span class="hljs-comment" style="color: rgb(136, 0, 0); box-sizing: border-box; font-family: 'Source Code Pro', monospace; font-size: 14px; line-height: 20.2999992370605px; white-space: pre; background-color: rgba(128, 128, 128, 0.0470588);"><!-- 这一行代表在MyCAT前端会显示哪些表名,类似几行都代表一样的意思,这里强调的是表,而MyCAT并不会在配置文件里面定义表结构,如果在前端使用show create table ,MyCAT会显示正常的表结构信息,观察Debug日志,可以看到,MyCAT把命令分发给了dn1代表的数据库,然后把dn1的查询结果返回给了前端 可以判断,类似的数据库级别的一些查询指令,有可能是单独分发给某个节点,然后再把某个节点的信息返回给前端。        dataNode的意义很简单,这个逻辑表的数据存储在后端的哪几个数据库里面rule代表的是这个逻辑表students的具体切分策略,目前MyCAT只支持按照某一个特殊列,遵循一些特殊的规则来切分,如取模,枚举等,具体的留给之后细说                              --></span><span style="color: rgb(51, 51, 51); font-family: 'Source Code Pro', monospace; font-size: 14px; line-height: 20.2999992370605px; white-space: pre; background-color: rgba(128, 128, 128, 0.0470588);">         </span><span class="hljs-tag" style="color: rgb(0, 102, 102); box-sizing: border-box; font-family: 'Source Code Pro', monospace; font-size: 14px; line-height: 20.2999992370605px; white-space: pre; background-color: rgba(128, 128, 128, 0.0470588);"><<span class="hljs-title" style="box-sizing: border-box; color: rgb(0, 0, 136);">table</span> <span class="hljs-attribute" style="box-sizing: border-box; color: rgb(102, 0, 102);">name</span>=<span class="hljs-value" style="box-sizing: border-box; color: rgb(0, 136, 0);">"travelrecord"</span> <span class="hljs-attribute" style="box-sizing: border-box; color: rgb(102, 0, 102);">dataNode</span>=<span class="hljs-value" style="box-sizing: border-box; color: rgb(0, 136, 0);">"dn1,dn2,dn3"</span> <span class="hljs-attribute" style="box-sizing: border-box; color: rgb(102, 0, 102);">rule</span>=<span class="hljs-value" style="box-sizing: border-box; color: rgb(0, 136, 0);">"auto-sharding-long"</span> /></span><span style="color: rgb(51, 51, 51); font-family: 'Source Code Pro', monospace; font-size: 14px; line-height: 20.2999992370605px; white-space: pre; background-color: rgba(128, 128, 128, 0.0470588);">        </span><span class="hljs-tag" style="color: rgb(0, 102, 102); box-sizing: border-box; font-family: 'Source Code Pro', monospace; font-size: 14px; line-height: 20.2999992370605px; white-space: pre; background-color: rgba(128, 128, 128, 0.0470588);"><<span class="hljs-title" style="box-sizing: border-box; color: rgb(0, 0, 136);">table</span> <span class="hljs-attribute" style="box-sizing: border-box; color: rgb(102, 0, 102);">name</span>=<span class="hljs-value" style="box-sizing: border-box; color: rgb(0, 136, 0);">"company"</span> <span class="hljs-attribute" style="box-sizing: border-box; color: rgb(102, 0, 102);">primaryKey</span>=<span class="hljs-value" style="box-sizing: border-box; color: rgb(0, 136, 0);">"ID"</span> <span class="hljs-attribute" style="box-sizing: border-box; color: rgb(102, 0, 102);">dataNode</span>=<span class="hljs-value" style="box-sizing: border-box; color: rgb(0, 136, 0);">"dn3,dn2,dn1"</span> <span class="hljs-attribute" style="box-sizing: border-box; color: rgb(102, 0, 102);">rule</span>=<span class="hljs-value" style="box-sizing: border-box; color: rgb(0, 136, 0);">"mod-long"</span>/></span><span style="color: rgb(51, 51, 51); font-family: 'Source Code Pro', monospace; font-size: 14px; line-height: 20.2999992370605px; white-space: pre; background-color: rgba(128, 128, 128, 0.0470588);">        </span><span class="hljs-tag" style="color: rgb(0, 102, 102); box-sizing: border-box; font-family: 'Source Code Pro', monospace; font-size: 14px; line-height: 20.2999992370605px; white-space: pre; background-color: rgba(128, 128, 128, 0.0470588);"><<span class="hljs-title" style="box-sizing: border-box; color: rgb(0, 0, 136);">table</span> <span class="hljs-attribute" style="box-sizing: border-box; color: rgb(102, 0, 102);">name</span>=<span class="hljs-value" style="box-sizing: border-box; color: rgb(0, 136, 0);">"goods"</span> <span class="hljs-attribute" style="box-sizing: border-box; color: rgb(102, 0, 102);">primaryKey</span>=<span class="hljs-value" style="box-sizing: border-box; color: rgb(0, 136, 0);">"ID"</span> <span class="hljs-attribute" style="box-sizing: border-box; color: rgb(102, 0, 102);">type</span>=<span class="hljs-value" style="box-sizing: border-box; color: rgb(0, 136, 0);">"global"</span> <span class="hljs-attribute" style="box-sizing: border-box; color: rgb(102, 0, 102);">dataNode</span>=<span class="hljs-value" style="box-sizing: border-box; color: rgb(0, 136, 0);">"dn1,dn2"</span> /></span><span style="color: rgb(51, 51, 51); font-family: 'Source Code Pro', monospace; font-size: 14px; line-height: 20.2999992370605px; white-space: pre; background-color: rgba(128, 128, 128, 0.0470588);">        </span><span class="hljs-comment" style="color: rgb(136, 0, 0); box-sizing: border-box; font-family: 'Source Code Pro', monospace; font-size: 14px; line-height: 20.2999992370605px; white-space: pre; background-color: rgba(128, 128, 128, 0.0470588);"><!--求模分片随机规则 --></span><span style="color: rgb(51, 51, 51); font-family: 'Source Code Pro', monospace; font-size: 14px; line-height: 20.2999992370605px; white-space: pre; background-color: rgba(128, 128, 128, 0.0470588);">        </span><span class="hljs-tag" style="color: rgb(0, 102, 102); box-sizing: border-box; font-family: 'Source Code Pro', monospace; font-size: 14px; line-height: 20.2999992370605px; white-space: pre; background-color: rgba(128, 128, 128, 0.0470588);"><<span class="hljs-title" style="box-sizing: border-box; color: rgb(0, 0, 136);">table</span> <span class="hljs-attribute" style="box-sizing: border-box; color: rgb(102, 0, 102);">name</span>=<span class="hljs-value" style="box-sizing: border-box; color: rgb(0, 136, 0);">"hotnews"</span> <span class="hljs-attribute" style="box-sizing: border-box; color: rgb(102, 0, 102);">primaryKey</span>=<span class="hljs-value" style="box-sizing: border-box; color: rgb(0, 136, 0);">"ID"</span> <span class="hljs-attribute" style="box-sizing: border-box; color: rgb(102, 0, 102);">dataNode</span>=<span class="hljs-value" style="box-sizing: border-box; color: rgb(0, 136, 0);">"dn1,dn2,dn3"</span>            <span class="hljs-attribute" style="box-sizing: border-box; color: rgb(102, 0, 102);">rule</span>=<span class="hljs-value" style="box-sizing: border-box; color: rgb(0, 136, 0);">"mod-long"</span> /></span><span style="color: rgb(51, 51, 51); font-family: 'Source Code Pro', monospace; font-size: 14px; line-height: 20.2999992370605px; white-space: pre; background-color: rgba(128, 128, 128, 0.0470588);">        </span><span class="hljs-tag" style="color: rgb(0, 102, 102); box-sizing: border-box; font-family: 'Source Code Pro', monospace; font-size: 14px; line-height: 20.2999992370605px; white-space: pre; background-color: rgba(128, 128, 128, 0.0470588);"><<span class="hljs-title" style="box-sizing: border-box; color: rgb(0, 0, 136);">table</span> <span class="hljs-attribute" style="box-sizing: border-box; color: rgb(102, 0, 102);">name</span>=<span class="hljs-value" style="box-sizing: border-box; color: rgb(0, 136, 0);">"employee"</span> <span class="hljs-attribute" style="box-sizing: border-box; color: rgb(102, 0, 102);">primaryKey</span>=<span class="hljs-value" style="box-sizing: border-box; color: rgb(0, 136, 0);">"ID"</span> <span class="hljs-attribute" style="box-sizing: border-box; color: rgb(102, 0, 102);">dataNode</span>=<span class="hljs-value" style="box-sizing: border-box; color: rgb(0, 136, 0);">"dn1,dn2"</span>            <span class="hljs-attribute" style="box-sizing: border-box; color: rgb(102, 0, 102);">rule</span>=<span class="hljs-value" style="box-sizing: border-box; color: rgb(0, 136, 0);">"sharding-by-intfile"</span> /></span><span style="color: rgb(51, 51, 51); font-family: 'Source Code Pro', monospace; font-size: 14px; line-height: 20.2999992370605px; white-space: pre; background-color: rgba(128, 128, 128, 0.0470588);">        </span><span class="hljs-tag" style="color: rgb(0, 102, 102); box-sizing: border-box; font-family: 'Source Code Pro', monospace; font-size: 14px; line-height: 20.2999992370605px; white-space: pre; background-color: rgba(128, 128, 128, 0.0470588);"><<span class="hljs-title" style="box-sizing: border-box; color: rgb(0, 0, 136);">table</span> <span class="hljs-attribute" style="box-sizing: border-box; color: rgb(102, 0, 102);">name</span>=<span class="hljs-value" style="box-sizing: border-box; color: rgb(0, 136, 0);">"customer"</span> <span class="hljs-attribute" style="box-sizing: border-box; color: rgb(102, 0, 102);">primaryKey</span>=<span class="hljs-value" style="box-sizing: border-box; color: rgb(0, 136, 0);">"ID"</span> <span class="hljs-attribute" style="box-sizing: border-box; color: rgb(102, 0, 102);">dataNode</span>=<span class="hljs-value" style="box-sizing: border-box; color: rgb(0, 136, 0);">"dn1,dn2"</span>            <span class="hljs-attribute" style="box-sizing: border-box; color: rgb(102, 0, 102);">rule</span>=<span class="hljs-value" style="box-sizing: border-box; color: rgb(0, 136, 0);">"sharding-by-intfile"</span>></span><span style="color: rgb(51, 51, 51); font-family: 'Source Code Pro', monospace; font-size: 14px; line-height: 20.2999992370605px; white-space: pre; background-color: rgba(128, 128, 128, 0.0470588);">             </span><span class="hljs-comment" style="color: rgb(136, 0, 0); box-sizing: border-box; font-family: 'Source Code Pro', monospace; font-size: 14px; line-height: 20.2999992370605px; white-space: pre; background-color: rgba(128, 128, 128, 0.0470588);"><!--                 childtable我在测试中并没有实际用起来不过在MyCAT的设计文档里面有提到,childtable是一种依赖于父表的结构,                这意味着,childtable的joinkey会按照父表的parentKey的策略一起切分,当父表与子表进行连接,                且连接条件是childtable.joinKey=parenttable.parentKey时,不会进行跨库的连接.                --></span><span style="color: rgb(51, 51, 51); font-family: 'Source Code Pro', monospace; font-size: 14px; line-height: 20.2999992370605px; white-space: pre; background-color: rgba(128, 128, 128, 0.0470588);">             </span><span class="hljs-tag" style="color: rgb(0, 102, 102); box-sizing: border-box; font-family: 'Source Code Pro', monospace; font-size: 14px; line-height: 20.2999992370605px; white-space: pre; background-color: rgba(128, 128, 128, 0.0470588);"><<span class="hljs-title" style="box-sizing: border-box; color: rgb(0, 0, 136);">childTable</span> <span class="hljs-attribute" style="box-sizing: border-box; color: rgb(102, 0, 102);">name</span>=<span class="hljs-value" style="box-sizing: border-box; color: rgb(0, 136, 0);">"orders"</span> <span class="hljs-attribute" style="box-sizing: border-box; color: rgb(102, 0, 102);">primaryKey</span>=<span class="hljs-value" style="box-sizing: border-box; color: rgb(0, 136, 0);">"ID"</span> <span class="hljs-attribute" style="box-sizing: border-box; color: rgb(102, 0, 102);">joinKey</span>=<span class="hljs-value" style="box-sizing: border-box; color: rgb(0, 136, 0);">"customer_id"</span>                <span class="hljs-attribute" style="box-sizing: border-box; color: rgb(102, 0, 102);">parentKey</span>=<span class="hljs-value" style="box-sizing: border-box; color: rgb(0, 136, 0);">"id"</span>></span><span style="color: rgb(51, 51, 51); font-family: 'Source Code Pro', monospace; font-size: 14px; line-height: 20.2999992370605px; white-space: pre; background-color: rgba(128, 128, 128, 0.0470588);">                </span><span class="hljs-tag" style="color: rgb(0, 102, 102); box-sizing: border-box; font-family: 'Source Code Pro', monospace; font-size: 14px; line-height: 20.2999992370605px; white-space: pre; background-color: rgba(128, 128, 128, 0.0470588);"><<span class="hljs-title" style="box-sizing: border-box; color: rgb(0, 0, 136);">childTable</span> <span class="hljs-attribute" style="box-sizing: border-box; color: rgb(102, 0, 102);">name</span>=<span class="hljs-value" style="box-sizing: border-box; color: rgb(0, 136, 0);">"order_items"</span> <span class="hljs-attribute" style="box-sizing: border-box; color: rgb(102, 0, 102);">joinKey</span>=<span class="hljs-value" style="box-sizing: border-box; color: rgb(0, 136, 0);">"order_id"</span>                    <span class="hljs-attribute" style="box-sizing: border-box; color: rgb(102, 0, 102);">parentKey</span>=<span class="hljs-value" style="box-sizing: border-box; color: rgb(0, 136, 0);">"id"</span> /></span><span style="color: rgb(51, 51, 51); font-family: 'Source Code Pro', monospace; font-size: 14px; line-height: 20.2999992370605px; white-space: pre; background-color: rgba(128, 128, 128, 0.0470588);">            </span><span class="hljs-tag" style="color: rgb(0, 102, 102); box-sizing: border-box; font-family: 'Source Code Pro', monospace; font-size: 14px; line-height: 20.2999992370605px; white-space: pre; background-color: rgba(128, 128, 128, 0.0470588);"></<span class="hljs-title" style="box-sizing: border-box; color: rgb(0, 0, 136);">childTable</span>></span><span style="color: rgb(51, 51, 51); font-family: 'Source Code Pro', monospace; font-size: 14px; line-height: 20.2999992370605px; white-space: pre; background-color: rgba(128, 128, 128, 0.0470588);">            </span><span class="hljs-tag" style="color: rgb(0, 102, 102); box-sizing: border-box; font-family: 'Source Code Pro', monospace; font-size: 14px; line-height: 20.2999992370605px; white-space: pre; background-color: rgba(128, 128, 128, 0.0470588);"><<span class="hljs-title" style="box-sizing: border-box; color: rgb(0, 0, 136);">childTable</span> <span class="hljs-attribute" style="box-sizing: border-box; color: rgb(102, 0, 102);">name</span>=<span class="hljs-value" style="box-sizing: border-box; color: rgb(0, 136, 0);">"customer_addr"</span> <span class="hljs-attribute" style="box-sizing: border-box; color: rgb(102, 0, 102);">primaryKey</span>=<span class="hljs-value" style="box-sizing: border-box; color: rgb(0, 136, 0);">"ID"</span> <span class="hljs-attribute" style="box-sizing: border-box; color: rgb(102, 0, 102);">joinKey</span>=<span class="hljs-value" style="box-sizing: border-box; color: rgb(0, 136, 0);">"customer_id"</span>                <span class="hljs-attribute" style="box-sizing: border-box; color: rgb(102, 0, 102);">parentKey</span>=<span class="hljs-value" style="box-sizing: border-box; color: rgb(0, 136, 0);">"id"</span> /></span><span style="color: rgb(51, 51, 51); font-family: 'Source Code Pro', monospace; font-size: 14px; line-height: 20.2999992370605px; white-space: pre; background-color: rgba(128, 128, 128, 0.0470588);">        </span><span class="hljs-tag" style="color: rgb(0, 102, 102); box-sizing: border-box; font-family: 'Source Code Pro', monospace; font-size: 14px; line-height: 20.2999992370605px; white-space: pre; background-color: rgba(128, 128, 128, 0.0470588);"></<span class="hljs-title" style="box-sizing: border-box; color: rgb(0, 0, 136);">table</span>></span><span style="color: rgb(51, 51, 51); font-family: 'Source Code Pro', monospace; font-size: 14px; line-height: 20.2999992370605px; white-space: pre; background-color: rgba(128, 128, 128, 0.0470588);">        </span><span class="hljs-comment" style="color: rgb(136, 0, 0); box-sizing: border-box; font-family: 'Source Code Pro', monospace; font-size: 14px; line-height: 20.2999992370605px; white-space: pre; background-color: rgba(128, 128, 128, 0.0470588);"><!-- 全局表是自动克隆到所有定义的数据节点,这样可以与拆分节点的任何表连接查询,是在同一个数据节点--></span><span style="color: rgb(51, 51, 51); font-family: 'Source Code Pro', monospace; font-size: 14px; line-height: 20.2999992370605px; white-space: pre; background-color: rgba(128, 128, 128, 0.0470588);">        </span><span class="hljs-tag" style="color: rgb(0, 102, 102); box-sizing: border-box; font-family: 'Source Code Pro', monospace; font-size: 14px; line-height: 20.2999992370605px; white-space: pre; background-color: rgba(128, 128, 128, 0.0470588);"><<span class="hljs-title" style="box-sizing: border-box; color: rgb(0, 0, 136);">table</span> <span class="hljs-attribute" style="box-sizing: border-box; color: rgb(102, 0, 102);">name</span>=<span class="hljs-value" style="box-sizing: border-box; color: rgb(0, 136, 0);">"news_table"</span> <span class="hljs-attribute" style="box-sizing: border-box; color: rgb(102, 0, 102);">primaryKey</span>=<span class="hljs-value" style="box-sizing: border-box; color: rgb(0, 136, 0);">"ID"</span> <span class="hljs-attribute" style="box-sizing: border-box; color: rgb(102, 0, 102);">type</span>=<span class="hljs-value" style="box-sizing: border-box; color: rgb(0, 136, 0);">"global"</span> <span class="hljs-attribute" style="box-sizing: border-box; color: rgb(102, 0, 102);">dataNode</span>=<span class="hljs-value" style="box-sizing: border-box; color: rgb(0, 136, 0);">"dn1,dn2,dn3"</span> /></span><span style="color: rgb(51, 51, 51); font-family: 'Source Code Pro', monospace; font-size: 14px; line-height: 20.2999992370605px; white-space: pre; background-color: rgba(128, 128, 128, 0.0470588);">    </span><span class="hljs-tag" style="color: rgb(0, 102, 102); box-sizing: border-box; font-family: 'Source Code Pro', monospace; font-size: 14px; line-height: 20.2999992370605px; white-space: pre; background-color: rgba(128, 128, 128, 0.0470588);"></<span class="hljs-title" style="box-sizing: border-box; color: rgb(0, 0, 136);">schema</span>></span><span style="color: rgb(51, 51, 51); font-family: 'Source Code Pro', monospace; font-size: 14px; line-height: 20.2999992370605px; white-space: pre; background-color: rgba(128, 128, 128, 0.0470588);">    </span><span class="hljs-tag" style="color: rgb(0, 102, 102); box-sizing: border-box; font-family: 'Source Code Pro', monospace; font-size: 14px; line-height: 20.2999992370605px; white-space: pre; background-color: rgba(128, 128, 128, 0.0470588);"><<span class="hljs-title" style="box-sizing: border-box; color: rgb(0, 0, 136);">dataNode</span> <span class="hljs-attribute" style="box-sizing: border-box; color: rgb(102, 0, 102);">name</span>=<span class="hljs-value" style="box-sizing: border-box; color: rgb(0, 136, 0);">"dn1"</span> <span class="hljs-attribute" style="box-sizing: border-box; color: rgb(102, 0, 102);">dataHost</span>=<span class="hljs-value" style="box-sizing: border-box; color: rgb(0, 136, 0);">"localhost1"</span> <span class="hljs-attribute" style="box-sizing: border-box; color: rgb(102, 0, 102);">database</span>=<span class="hljs-value" style="box-sizing: border-box; color: rgb(0, 136, 0);">"mycatDB1"</span> /></span><span style="color: rgb(51, 51, 51); font-family: 'Source Code Pro', monospace; font-size: 14px; line-height: 20.2999992370605px; white-space: pre; background-color: rgba(128, 128, 128, 0.0470588);">    </span><span class="hljs-tag" style="color: rgb(0, 102, 102); box-sizing: border-box; font-family: 'Source Code Pro', monospace; font-size: 14px; line-height: 20.2999992370605px; white-space: pre; background-color: rgba(128, 128, 128, 0.0470588);"><<span class="hljs-title" style="box-sizing: border-box; color: rgb(0, 0, 136);">dataNode</span> <span class="hljs-attribute" style="box-sizing: border-box; color: rgb(102, 0, 102);">name</span>=<span class="hljs-value" style="box-sizing: border-box; color: rgb(0, 136, 0);">"dn2"</span> <span class="hljs-attribute" style="box-sizing: border-box; color: rgb(102, 0, 102);">dataHost</span>=<span class="hljs-value" style="box-sizing: border-box; color: rgb(0, 136, 0);">"localhost1"</span> <span class="hljs-attribute" style="box-sizing: border-box; color: rgb(102, 0, 102);">database</span>=<span class="hljs-value" style="box-sizing: border-box; color: rgb(0, 136, 0);">"mycatDB2"</span> /></span><span style="color: rgb(51, 51, 51); font-family: 'Source Code Pro', monospace; font-size: 14px; line-height: 20.2999992370605px; white-space: pre; background-color: rgba(128, 128, 128, 0.0470588);">    </span><span class="hljs-tag" style="color: rgb(0, 102, 102); box-sizing: border-box; font-family: 'Source Code Pro', monospace; font-size: 14px; line-height: 20.2999992370605px; white-space: pre; background-color: rgba(128, 128, 128, 0.0470588);"><<span class="hljs-title" style="box-sizing: border-box; color: rgb(0, 0, 136);">dataNode</span> <span class="hljs-attribute" style="box-sizing: border-box; color: rgb(102, 0, 102);">name</span>=<span class="hljs-value" style="box-sizing: border-box; color: rgb(0, 136, 0);">"dn3"</span> <span class="hljs-attribute" style="box-sizing: border-box; color: rgb(102, 0, 102);">dataHost</span>=<span class="hljs-value" style="box-sizing: border-box; color: rgb(0, 136, 0);">"localhost1"</span> <span class="hljs-attribute" style="box-sizing: border-box; color: rgb(102, 0, 102);">database</span>=<span class="hljs-value" style="box-sizing: border-box; color: rgb(0, 136, 0);">"mycatDB3"</span> /></span><span style="color: rgb(51, 51, 51); font-family: 'Source Code Pro', monospace; font-size: 14px; line-height: 20.2999992370605px; white-space: pre; background-color: rgba(128, 128, 128, 0.0470588);">    </span><span class="hljs-comment" style="color: rgb(136, 0, 0); box-sizing: border-box; font-family: 'Source Code Pro', monospace; font-size: 14px; line-height: 20.2999992370605px; white-space: pre; background-color: rgba(128, 128, 128, 0.0470588);"><!--          dataHost配置的是实际的后端数据库集群,大部分参数简单易懂,这里就不一个个介绍了,只介绍比较重要的两个参数,writeType和balance.         --></span><span style="color: rgb(51, 51, 51); font-family: 'Source Code Pro', monospace; font-size: 14px; line-height: 20.2999992370605px; white-space: pre; background-color: rgba(128, 128, 128, 0.0470588);">         </span><span class="hljs-comment" style="color: rgb(136, 0, 0); box-sizing: border-box; font-family: 'Source Code Pro', monospace; font-size: 14px; line-height: 20.2999992370605px; white-space: pre; background-color: rgba(128, 128, 128, 0.0470588);"><!-- writeType和balance是用来控制后端集群的读写分离的关键参数,这里我用了双主双从的集群配置            这里的测试过程比较麻烦,所以直接贴结论:           1.balance=0时,读操作都在localhost上(localhost失败时,后端直接失败)           2.balance=1时,读操作会随机分散在localhost1和两个readhost上面(localhost失败时,写操作会在localhost1,如果localhost1再失败,则无法进行写操作)           3.balance=2时,写操作会在localhost上,读操作会随机分散在localhost1,localhost1和两个readhost上面(同上)           4.writeType=0时,写操作会在localhost上,如果localhost失败,会自动切换到localhost1,localhost恢复以后并不会切换回localhost进行写操作           5.writeType=1时,写操作会随机分布在localhost和localhost1上,单点失败并不会影响集群的写操作,但是后端的从库会无法从挂掉的主库获取更新,会在读数据的时候出现数据不一致           举例:localhost失败了,写操作会在localhost1上面进行,localhost1的主从正常运行,但是localhost的从库无法从localhost获取更新,localhost的从库于其他库出现数据不一致         --></span><span style="color: rgb(51, 51, 51); font-family: 'Source Code Pro', monospace; font-size: 14px; line-height: 20.2999992370605px; white-space: pre; background-color: rgba(128, 128, 128, 0.0470588);">     </span><span class="hljs-tag" style="color: rgb(0, 102, 102); box-sizing: border-box; font-family: 'Source Code Pro', monospace; font-size: 14px; line-height: 20.2999992370605px; white-space: pre; background-color: rgba(128, 128, 128, 0.0470588);"><<span class="hljs-title" style="box-sizing: border-box; color: rgb(0, 0, 136);">dataHost</span> <span class="hljs-attribute" style="box-sizing: border-box; color: rgb(102, 0, 102);">name</span>=<span class="hljs-value" style="box-sizing: border-box; color: rgb(0, 136, 0);">"localhost1"</span> <span class="hljs-attribute" style="box-sizing: border-box; color: rgb(102, 0, 102);">maxCon</span>=<span class="hljs-value" style="box-sizing: border-box; color: rgb(0, 136, 0);">"1000"</span> <span class="hljs-attribute" style="box-sizing: border-box; color: rgb(102, 0, 102);">minCon</span>=<span class="hljs-value" style="box-sizing: border-box; color: rgb(0, 136, 0);">"10"</span> <span class="hljs-attribute" style="box-sizing: border-box; color: rgb(102, 0, 102);">balance</span>=<span class="hljs-value" style="box-sizing: border-box; color: rgb(0, 136, 0);">"0"</span>        <span class="hljs-attribute" style="box-sizing: border-box; color: rgb(102, 0, 102);">writeType</span>=<span class="hljs-value" style="box-sizing: border-box; color: rgb(0, 136, 0);">"0"</span> <span class="hljs-attribute" style="box-sizing: border-box; color: rgb(102, 0, 102);">dbType</span>=<span class="hljs-value" style="box-sizing: border-box; color: rgb(0, 136, 0);">"mysql"</span> <span class="hljs-attribute" style="box-sizing: border-box; color: rgb(102, 0, 102);">dbDriver</span>=<span class="hljs-value" style="box-sizing: border-box; color: rgb(0, 136, 0);">"native"</span> <span class="hljs-attribute" style="box-sizing: border-box; color: rgb(102, 0, 102);">switchType</span>=<span class="hljs-value" style="box-sizing: border-box; color: rgb(0, 136, 0);">"1"</span>  <span class="hljs-attribute" style="box-sizing: border-box; color: rgb(102, 0, 102);">slaveThreshold</span>=<span class="hljs-value" style="box-sizing: border-box; color: rgb(0, 136, 0);">"100"</span>></span><span style="color: rgb(51, 51, 51); font-family: 'Source Code Pro', monospace; font-size: 14px; line-height: 20.2999992370605px; white-space: pre; background-color: rgba(128, 128, 128, 0.0470588);">        </span><span class="hljs-tag" style="color: rgb(0, 102, 102); box-sizing: border-box; font-family: 'Source Code Pro', monospace; font-size: 14px; line-height: 20.2999992370605px; white-space: pre; background-color: rgba(128, 128, 128, 0.0470588);"><<span class="hljs-title" style="box-sizing: border-box; color: rgb(0, 0, 136);">heartbeat</span>></span><span style="color: rgb(51, 51, 51); font-family: 'Source Code Pro', monospace; font-size: 14px; line-height: 20.2999992370605px; white-space: pre; background-color: rgba(128, 128, 128, 0.0470588);">select user()</span><span class="hljs-tag" style="color: rgb(0, 102, 102); box-sizing: border-box; font-family: 'Source Code Pro', monospace; font-size: 14px; line-height: 20.2999992370605px; white-space: pre; background-color: rgba(128, 128, 128, 0.0470588);"></<span class="hljs-title" style="box-sizing: border-box; color: rgb(0, 0, 136);">heartbeat</span>></span><span style="color: rgb(51, 51, 51); font-family: 'Source Code Pro', monospace; font-size: 14px; line-height: 20.2999992370605px; white-space: pre; background-color: rgba(128, 128, 128, 0.0470588);">        </span><span class="hljs-comment" style="color: rgb(136, 0, 0); box-sizing: border-box; font-family: 'Source Code Pro', monospace; font-size: 14px; line-height: 20.2999992370605px; white-space: pre; background-color: rgba(128, 128, 128, 0.0470588);"><!-- can have multi write hosts --></span><span style="color: rgb(51, 51, 51); font-family: 'Source Code Pro', monospace; font-size: 14px; line-height: 20.2999992370605px; white-space: pre; background-color: rgba(128, 128, 128, 0.0470588);">        </span><span class="hljs-tag" style="color: rgb(0, 102, 102); box-sizing: border-box; font-family: 'Source Code Pro', monospace; font-size: 14px; line-height: 20.2999992370605px; white-space: pre; background-color: rgba(128, 128, 128, 0.0470588);"><<span class="hljs-title" style="box-sizing: border-box; color: rgb(0, 0, 136);">writeHost</span> <span class="hljs-attribute" style="box-sizing: border-box; color: rgb(102, 0, 102);">host</span>=<span class="hljs-value" style="box-sizing: border-box; color: rgb(0, 136, 0);">"hostM1"</span> <span class="hljs-attribute" style="box-sizing: border-box; color: rgb(102, 0, 102);">url</span>=<span class="hljs-value" style="box-sizing: border-box; color: rgb(0, 136, 0);">"localhost:3306"</span> <span class="hljs-attribute" style="box-sizing: border-box; color: rgb(102, 0, 102);">user</span>=<span class="hljs-value" style="box-sizing: border-box; color: rgb(0, 136, 0);">"root"</span>            <span class="hljs-attribute" style="box-sizing: border-box; color: rgb(102, 0, 102);">password</span>=<span class="hljs-value" style="box-sizing: border-box; color: rgb(0, 136, 0);">"123456"</span>></span><span style="color: rgb(51, 51, 51); font-family: 'Source Code Pro', monospace; font-size: 14px; line-height: 20.2999992370605px; white-space: pre; background-color: rgba(128, 128, 128, 0.0470588);">            </span><span class="hljs-comment" style="color: rgb(136, 0, 0); box-sizing: border-box; font-family: 'Source Code Pro', monospace; font-size: 14px; line-height: 20.2999992370605px; white-space: pre; background-color: rgba(128, 128, 128, 0.0470588);"><!-- can have multi read hosts --></span><span style="color: rgb(51, 51, 51); font-family: 'Source Code Pro', monospace; font-size: 14px; line-height: 20.2999992370605px; white-space: pre; background-color: rgba(128, 128, 128, 0.0470588);">            </span><span class="hljs-comment" style="color: rgb(136, 0, 0); box-sizing: border-box; font-family: 'Source Code Pro', monospace; font-size: 14px; line-height: 20.2999992370605px; white-space: pre; background-color: rgba(128, 128, 128, 0.0470588);"><!--<readHost host="hostS2" url="192.168.1.200:3306" user="root" password="xxx" />--></span><span style="color: rgb(51, 51, 51); font-family: 'Source Code Pro', monospace; font-size: 14px; line-height: 20.2999992370605px; white-space: pre; background-color: rgba(128, 128, 128, 0.0470588);">        </span><span class="hljs-tag" style="color: rgb(0, 102, 102); box-sizing: border-box; font-family: 'Source Code Pro', monospace; font-size: 14px; line-height: 20.2999992370605px; white-space: pre; background-color: rgba(128, 128, 128, 0.0470588);"></<span class="hljs-title" style="box-sizing: border-box; color: rgb(0, 0, 136);">writeHost</span>></span><span style="color: rgb(51, 51, 51); font-family: 'Source Code Pro', monospace; font-size: 14px; line-height: 20.2999992370605px; white-space: pre; background-color: rgba(128, 128, 128, 0.0470588);">    </span><span class="hljs-tag" style="color: rgb(0, 102, 102); box-sizing: border-box; font-family: 'Source Code Pro', monospace; font-size: 14px; line-height: 20.2999992370605px; white-space: pre; background-color: rgba(128, 128, 128, 0.0470588);"></<span class="hljs-title" style="box-sizing: border-box; color: rgb(0, 0, 136);">dataHost</span>></span><span style="color: rgb(51, 51, 51); font-family: 'Source Code Pro', monospace; font-size: 14px; line-height: 20.2999992370605px; white-space: pre; background-color: rgba(128, 128, 128, 0.0470588);"></span><span class="hljs-tag" style="color: rgb(0, 102, 102); box-sizing: border-box; font-family: 'Source Code Pro', monospace; font-size: 14px; line-height: 20.2999992370605px; white-space: pre; background-color: rgba(128, 128, 128, 0.0470588);"></<span class="hljs-title" style="box-sizing: border-box; color: rgb(0, 0, 136);">mycat:schema</span>></span>

<?xml version="1.0" encoding="UTF-8"?><!-- - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. --><!DOCTYPE mycat:server SYSTEM "server.dtd"><mycat:serverxmlns:mycat="http://org.opencloudb/"><system><propertyname="defaultSqlParser">druidparser</property><!-- <property name="useCompression">1</property>--><!--1为开启mysql压缩协议--><!-- <property name="processorBufferChunk">40960</property> --><!-- <property name="processors">1</property> <property name="processorExecutor">32</property> --><!--默认是65535 64K 用于sql解析时最大文本长度 --><!--<property name="maxStringLiteralLength">65535</property>--><!--<property name="sequnceHandlerType">0</property>--><!--<property name="backSocketNoDelay">1</property>--><!--<property name="frontSocketNoDelay">1</property>--><!--<property name="processorExecutor">16</property>--><!-- <property name="mutiNodeLimitType">1</property> 0:开启小数量级(默认) ;1:开启亿级数据排序 <property name="mutiNodePatchSize">100</property> 亿级数量排序批量 <property name="processors">32</property> <property name="processorExecutor">32</property> <property name="serverPort">8066</property> <property name="managerPort">9066</property> <property name="idleTimeout">300000</property> <property name="bindIp">0.0.0.0</property> <property name="frontWriteQueueSize">4096</property> <property name="processors">32</property> --></system><username="test"><!--用户名--><propertyname="password">test</property><!--密码--><!--实例名,和schema.xml定义的schema对应,这里的实例名是虚拟名,也就是对mycat服务的一种别名,是应用程序以及客户端连接的入口。--><propertyname="schemas">TESTDB</property></user><username="user"><propertyname="password">user</property><propertyname="schemas">TESTDB</property><propertyname="readOnly">true</property></user><!-- <quarantine> <whitehost> <host host="127.0.0.1" user="mycat"/> <host host="127.0.0.2" user="mycat"/> </whitehost> <blacklist check="false"></blacklist> </quarantine> --></mycat:server>

rule.xml配置文

<?xml version="1.0" encoding="UTF-8"?> <!-- - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. --> <!DOCTYPE mycat:rule SYSTEM "rule.dtd"> <mycat:rulexmlns:mycat="http://org.opencloudb/"> <tableRulename="rule1"> <rule> <columns> id </columns> <algorithm> func1 </algorithm> </rule> </tableRule> <tableRulename="rule2"> <rule> <columns> user_id </columns> <algorithm> func1 </algorithm> </rule> </tableRule> <tableRulename="sharding-by-intfile"> <rule> <columns> sharding_id </columns> <algorithm> hash-int </algorithm> </rule> </tableRule> <tableRulename="auto-sharding-long"> <rule> <columns> id </columns> <algorithm> rang-long </algorithm> </rule> </tableRule> <tableRulename="mod-long"> <rule> <columns> id </columns> <algorithm> mod-long </algorithm> </rule> </tableRule> <tableRulename="sharding-by-murmur"> <rule> <columns> id </columns> <algorithm> murmur </algorithm> </rule> </tableRule> <tableRulename="sharding-by-month"> <rule> <columns> create_date </columns> <algorithm> partbymonth </algorithm> </rule> </tableRule> <tableRulename="latest-month-calldate"> <rule> <columns> calldate </columns> <algorithm> latestMonth </algorithm> </rule> </tableRule> <tableRulename="auto-sharding-rang-mod"> <rule> <columns> id </columns> <algorithm> rang-mod </algorithm> </rule> </tableRule> <tableRulename="jch"> <rule> <columns> id </columns> <algorithm> jump-consistent-hash </algorithm> </rule> </tableRule> <functionname="murmur"class="org.opencloudb.route.function.PartitionByMurmurHash"> <propertyname="seed"> 0 </property> <!-- 默认是0 --> <propertyname="count"> 2 </property> <!-- 要分片的数据库节点数量,必须指定,否则没法分片 --> <propertyname="virtualBucketTimes"> 160 </property> <!-- 一个实际的数据库节点被映射为这么多虚拟节点,默认是160倍,也就是虚拟节点数是物理节点数的160倍 --> <!-- <property name="weightMapFile">weightMapFile</property> 节点的权重,没有指定权重的节点默认是1。以properties文件的格式填写,以从0开始到count-1的整数值也就是节点索引为key,以节点权重值为值。所有权重值必须是正整数,否则以1代替 --> <!-- <property name="bucketMapPath">/etc/mycat/bucketMapPath</property> 用于测试时观察各物理节点与虚拟节点的分布情况,如果指定了这个属性,会把虚拟节点的murmur hash值与物理节点的映射按行输出到这个文件,没有默认值,如果不指定,就不会输出任何东西 --> </function> <functionname="hash-int"class="org.opencloudb.route.function.PartitionByFileMap"> <propertyname="mapFile"> partition-hash-int.txt </property> </function> <functionname="rang-long"class="org.opencloudb.route.function.AutoPartitionByLong"> <propertyname="mapFile"> autopartition-long.txt </property> </function> <functionname="mod-long"class="org.opencloudb.route.function.PartitionByMod"> <!-- how many data nodes --> <propertyname="count"> 3 </property> </function> <functionname="func1"class="org.opencloudb.route.function.PartitionByLong"> <propertyname="partitionCount"> 8 </property> <propertyname="partitionLength"> 128 </property> </function> <functionname="latestMonth"class="org.opencloudb.route.function.LatestMonthPartion"> <propertyname="splitOneDay"> 24 </property> </function> <functionname="partbymonth"class="org.opencloudb.route.function.PartitionByMonth"> <propertyname="dateFormat"> yyyy-MM-dd </property> <propertyname="sBeginDate"> 2015-01-01 </property> </function> <functionname="rang-mod"class="org.opencloudb.route.function.PartitionByRangeMod"> <propertyname="mapFile"> partition-range-mod.txt </property> </function> <functionname="jump-consistent-hash"class="org.opencloudb.route.function.PartitionByJumpConsistentHash"> <propertyname="totalBuckets"> 3 </property> </function> </mycat:rule>

Mycat连接mysql示例


cmd命令运行: 
这里写图片描述 
结果: 
这里写图片描述

Mycat连接mysql结果

这里写图片描述 
这里写图片描述 
上图上面的mycatdb1,mycatdb2,mycatdb3数据库是真实物理数据库,TESTDB是中间件逻辑数据库,此时已经所有工作都准备好。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Windows环境Mycat数据库分库分表中间件部署 的相关文章

  • 如何防止大型 MySQL 导入的连接超时

    在开发过程中 我们的本地 WAMP 服务器如何从测试服务器获取最新数据 即生成数据库转储 然后使用 source 命令上传该转储以加载 sql 文件 最近 在导入的最后 我们收到了有关 old 变量的错误 这些变量在更改之前存储了原始设置
  • MySQL - 重命名列

    如何重命名 mysql 列help to content在我的桌子上tbl help mysql query ALTER TABLE tbl help CHANGE COLUMN help content 您必须在更改列语句中包含列的定义
  • 使用 Coldfusion 分页

    是否可以仅使用一个查询在 Coldfusion 中分页并显示页数 我的理解是 您显然可以使用一个查询进行分页 但您需要一个额外的查询来创建页面 这是为了计算结果总数 currentPage 1 resultsPerPage Offset i
  • 通过左连接实现精确分页

    我已经思考这个问题有一段时间了 我认为最好四处询问并听听其他人的想法 我正在构建一个在 Mysql 上存储位置的系统 每个位置都有一个类型 有些位置有多个地址 表格看起来像这样 location location id autoincrem
  • 为什么我们要关闭 Mysqli 中的结果

    为什么我们要关闭 result mysqli new mysqli localhost root root test if mysqli gt connect errno echo Failed to connect to MySQL my
  • MAMP Python-MySQLdb 问题:调用 Python 文件后 libssl.1.0.0.dylib 的路径发生变化

    我正在尝试使用 python MySQLdb 访问 MAMP 服务器上的 MySQL 数据库 当我最初尝试使用 python sql 调用 Python 文件来访问 MAMP 上的数据库时 我得到了image not found关于错误li
  • mysql - 有什么方法可以帮助使用另一个索引进行全文搜索?

    假设我有一个 文章 表 其中包含以下列 article text fulltext indexed author id indexed 现在我想搜索特定作者撰写的文章中出现的术语 所以像这样 select from articles whe
  • MySQL 性能 DELETE 或 UPDATE?

    我有一个超过 10 7 行的 MyISAM 表 向其中添加数据时 我必须在最后更新 10 行 删除它们然后插入新行更快 还是更新这些行更快 应更新的数据不是索引的一部分 索引 数据碎片怎么样 UPDATE到目前为止要快得多 当你UPDATE
  • 在旧版本的 MySQL (<5.5.0) 中模拟 TO_SECONDS()

    出于性能和简单性的原因 我想以秒的形式获取 MySQL 3 x 服务器中 DATETIME 列的内容 或者实际上任何数字类型 我只是想在使用 UNIX TIMESTAMP 时避免所有明显的时区问题 the我表中的日期确实来自不同的区域设置
  • 启动服务器后,带有sequelize的Nodejs无法在mysql工作台中创建表

    我开始学习如何使用构建 Rest APINodejs Expressjs Sequelize and MySQL using Mysqlworkbench 我的问题 启动服务器后 该表不是由Sequelize并且没有表Mysqlworkbe
  • Doctrine 不会在 MySQL 中生成跨数据库外键约束

    我有两个表 db1 Contact 和 db2 Recipient 每个收件人都应该是联系人 因此我在 db1 Contact ContactID 字段上的两个表之间设置了外键 我在 Recipient php 中使用以下注释表示这一点 O
  • 哈希 MySQL 数据库架构

    我想对 MySQL 数据库模式 没有数据 进行哈希 签名 以便对其进行校验和 以确保它不被其他人修改 我怎样才能实现它 据我了解您的问题 您需要表校验和 checksum table table 所以 我想 只需对空表进行校验和
  • ZeroDateTimeBehavior=convertToNull 在使用 hibernate 的 jdbc url 中不起作用

    通过 extern 属性文件 url 指定如下 jdbc mariadb xxxxx 3306 xxxxx zeroDateTimeBehavior convertToNull 连接工作正常并且能够查询数据库 通过休眠 我创建了一个映射到带
  • 将 Python 列表(JSON 或其他)插入 MySQL 数据库

    所以我在Python中有一堆数组数据 嗯 相反 我有一个清单 我试图将此数组存储到 MySQL 数据库中的单个单元格中 我尝试使用 JSON 来序列化我的数据 但也许我不明白 JSON 是如何工作的 因此 在连接到我的数据库后 我尝试了上游
  • IMAP 和 PHP - 从已发送文件夹和收件箱文件夹中获取所有电子邮件

    我正在尝试获取接收和发送的所有电子邮件 并使用 PHP 将其写入 mySQL 数据库 我使用的主机名是 hostname imap gmail com 993 imap ssl INBOX 它仅引用收件箱 并成功抓取收到的电子邮件 为了抓取
  • Delphi XE5 FireDAC 错误:无法加载供应商库 [libmysql.dll 或 libmysqld.dll]

    我在 Windows 7 64 位上使用 Delphi XE5 只是尝试 FireDAC 组件 我正在使用一个 TFDConnection 组件连接到本地 MySQL 数据库 v5 6 15 我已经将 libmysql dll 32位 v5
  • 通过 PDO 将双精度数插入 MySQL 时精度损失

    我遇到了这种非常烦人的行为 我想知道我是否做错了什么 或者这是否是故意的 如果是的话 为什么 每当我在 php 5 3 中有一个 double 类型的变量 并且想将其插入到数据库 MYSQL 5 0 的 double 类型字段中时 该值总是
  • 如何在 MySQL 中启用严格 sql_mode?

    我怎样才能启用严格sql mode在 MySQL 中 我想从 SQL 中获取数据并在中处理相同的数据strict mode 我现在的sql mode is mysql gt SELECT sql mode sql mode NO ENGIN
  • 如何限制两个表之间一对多关系中的多个数量?

    我有一个带有两个 MySql 表的 MySQL 数据库 第一个是第一个表 表 A 有一列具有唯一值 从值 从 1 到 n 在第二个表 2 表 B 中 我有两列 在第一个表中我有一个名称 在第二个我的值从 1 到 n 如果我在 中添加一个值
  • 如何更新 MySQL 数据库中的两列?

    这不起作用 UPDATE customers SET firstname John AND lastname Smith WHERE id 1 用逗号分隔值 AND是一个逻辑运算符 它的位置是WHERE and ON条款 UPDATE cu

随机推荐

  • 13个你可能未使用过的Python教程!

    Python 是顶级编程语言之一 它具有许多程序员从未使用过的许多隐藏功能 在这篇博客中 我将分享你可能从未使用过的13 个 Python 特性 列表Stepping 这是一个 step 参数 可以通过采取几个步骤来分割你的列表 此外 你可
  • Mybatis-多表联查

    多表联查 一 步骤一 创建pojo实体类 二 步骤二 明确两个实体类之间的关系 三 步骤三 修改pojo实体类 四 步骤四 编写Mapper接口 五 步骤五 编写Mapper映射文件 题目1 通过订单id查询订单详情以及所属用户 题目2 通
  • mysql字段更新拼接_更新数据库中值为拼接字符串的字段

    我们开发系统涉及权限的时候 会处理到用户和角色的关系 通常情况下 我们会建一个用户角色关系映射表 user role mapping 字段有id user id role id 如果某个用户有多个角色 那么在user role mappin
  • C语言课程设计学生籍贯信息,C语言课程设计 学生籍贯信息记录簿设计.doc

    C语言与程序设计课程设计 学生籍贯信息记录簿设计 学 院 信息工程 班 级 物联1301班 学 号 131408119 姓 名 滕玲 一 设计目的 该软件主要是编辑一个学生籍贯信息记录簿记录每个学生信息 包括 学号 姓名 籍贯 具体功能 1
  • flex布局采用justify-content:space-between时,当为两个内容时中间被空出的解决方案

    我们在用flex布局的时候有时会用到justify content space between属性 这个属性是让弹性容器内的元素向两端对齐 div class box div div div div div div div div div
  • 广度优先遍历进阶

    第七周 BFS 广度优先搜索 733 127 130 317 505 529 1263 1197 815 934 广度优先模板 void bfs queue
  • filetime,systemtime相互转化,获取文件创建时间,访问时间,修改时间,获取指定时间之前之后的SYSTEMTIME

    deleteOldFiles cpp 定义控制台应用程序的入口点 include stdafx h include
  • 脑科学和类脑智能技术综述学习笔记

    文章目录 Part1 脑科学 1 脑科学与类脑研究概述 摘要 引言 1 国际脑科学和类脑研究的回顾与前瞻 1 1 脑科学的回顾 现代神经科学的起点是 神经解剖学和组织学 对神经系统结构的认识和分析 1 2 脑科学领域的重大问题 从图谱制作到
  • Unity3d实现红外热成像效果

    1 将需要在红外图像中高亮的物体设置到图层PostProcessing 2 新建一个相机CameraHighLight 设置其Culling Mask为PostProcessing 也就是在这个相机中只有PostProcessing图层的物
  • ArcGIS Pro免费试用申请与安装配置

    ArcGIS Pro免费试用申请与安装配置 每个邮箱可以申请21天的试用 1 打开申请网站 https www esri com zh cn arcgis products arcgis pro trial 2 注册ArcGIS试用 3 在
  • JS子窗口向父窗口传值

    方法一 用模式窗口 returnValue是javascript中html的window对象的属性 目的是返回窗口值 当用window showModalDialog函数打开一个IE的模式窗口 模式窗口就是子窗口 打开后不能操作父窗口 只能
  • 斐波那契数列求和——C语言(小白版)

    斐波那契数列求和 C语言 小白版 题目要求 斐波那契数列 1 1 2 3 5 8 13 21 34 不难发现当n gt 2时 an an 1 an 2 要求 当屏幕输入n n gt 2 时 输出前n项以及前n项的和 注意 我们不使用递归 也
  • 使用Qt创建模拟时钟

    main cpp include
  • Java的数据结构之枚举、向量、栈、字典

    Java工具包提供了强大的数据结构 在Java中的数据结构主要包括以下几种接口和类 枚举 Enumeration 位集合 BitSet 向量 Vector 栈 Stack 字典 Dictionary 哈希表 Hashtable 属性 Pro
  • Java Character 类

    Character 类用于对单个字符进行操作 Character 类在对象中包装一个基本类型 char 的值 实例 char ch a Unicode 字符表示形式 char uniChar u039A 字符数组 char charArra
  • 实战演习(五)——人脸识别(CNN)简单演练

    笔者是一个痴迷于挖掘数据中的价值的学习人 希望在平日的工作学习中 挖掘数据的价值 找寻数据的秘密 笔者认为 数据的价值不仅仅只体现在企业中 个人也可以体会到数据的魅力 用技术力量探索行为密码 让大数据助跑每一个人 欢迎直筒们关注我的公众号
  • 运输层协议概述

    紫色代表一级目录 粉红代表二级目录 蓝色代表三级目录 红色代表关键字 橙色代表说明 运输层协议概述 进程之间的通信 从通信的角度看 运输层向它上面的应用层提供通信服务 它属于面向通信部分的最高层 从信息处理的角度看 运输层是用户功能中的最低
  • 【陈工笔记】# LaTeX中,单元格数据居中方式 #

    良好的习惯 才不会让努力白白浪费 第一种方式 使用 p 1 5cm lt centering 指定单元格大小并设置对齐 其中p 1 5cm 指定大小 lt centering 指定对齐方式 使用 lt centering 时 需引入宏包 u
  • 点云学习---入门

    1 点云数据格式 常见的点云格式包括 las 用于激光雷达点云及其他任何三维xyz元组 是一种用于交换三维点数据的公共文件格式 文件主要由4部分组成 包括公共头块 包含版本号 缩放因子 偏移值 时间 范围等 变长记录 包含变长类型数据 坐标
  • Windows环境Mycat数据库分库分表中间件部署

    Windows环境Mycat数据库分库分表中间件部署 标签 数据库中间件mycat分布式集群 2016 08 23 00 17 957人阅读 评论 0 收藏 举报 分类 分布式开发技术 12 版权声明 本文为博主原创文章 未经博主允许不得转