windows下配置mycat,实现mysql数据库的读写分离!

下载Windows的安装包

https://github.com/MyCATApache/Mycat-download/tree/master/1.4-RELEASE下的

windows下配置mycat,实现mysql数据库的读写分离!


windows下配置mycat,实现mysql数据库的读写分离!


配置环境变量:


windows下配置mycat,实现mysql数据库的读写分离!

windows下配置mycat,实现mysql数据库的读写分离!

修改配置文件

windows下配置mycat,实现mysql数据库的读写分离!

wrapper.conf

windows下配置mycat,实现mysql数据库的读写分离!


Server.xml

windows下配置mycat,实现mysql数据库的读写分离!


[html] view plain copy
  1. <?xml version="1.0" encoding="UTF-8"?>  
  2. <!-- - - Licensed under the Apache License, Version 2.0 (the "License");   
  3.     - you may not use this file except in compliance with the License. - You   
  4.     may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0   
  5.     - - Unless required by applicable law or agreed to in writing, software -   
  6.     distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT   
  7.     WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the   
  8.     License for the specific language governing permissions and - limitations   
  9.     under the License. -->  
  10. <!DOCTYPE mycat:server SYSTEM "server.dtd">  
  11. <mycat:server xmlns:mycat="http://org.opencloudb/">  
  12.     <system>  
  13.     <property name="defaultSqlParser">druidparser</property>  
  14.       <!--  <property name="useCompression">1</property>--> <!--1为开启mysql压缩协议-->  
  15.     <!-- <property name="processorBufferChunk">40960</property> -->  
  16.     <!--   
  17.     <property name="processors">1</property>   
  18.     <property name="processorExecutor">32</property>   
  19.      -->  
  20.         <!--默认是65535 64K 用于sql解析时最大文本长度 -->  
  21.         <!--<property name="maxStringLiteralLength">65535</property>-->  
  22.         <!--<property name="sequnceHandlerType">0</property>-->  
  23.         <!--<property name="backSocketNoDelay">1</property>-->  
  24.         <!--<property name="frontSocketNoDelay">1</property>-->  
  25.         <!--<property name="processorExecutor">16</property>-->  
  26.         <!--   
  27.             <property name="mutiNodeLimitType">1</property> 0:开启小数量级(默认) ;1:开启亿级数据排序  
  28.             <property name="mutiNodePatchSize">100</property> 亿级数量排序批量  
  29.             <property name="processors">32</property> <property name="processorExecutor">32</property>   
  30.             <property name="serverPort">8066</property> <property name="managerPort">9066</property>   
  31.             <property name="idleTimeout">300000</property> <property name="bindIp">0.0.0.0</property>   
  32.             <property name="frontWriteQueueSize">4096</property> <property name="processors">32</property> -->  
  33.     </system>  
  34.     <user name="root">  
  35.         <property name="password">zhangxin</property>  
  36.         <property name="schemas">TESTDB</property>  
  37.     </user>  
  38.   
  39.     <user name="test">  
  40.         <property name="password">123456</property>  
  41.         <property name="schemas">TESTDB</property>  
  42.         <property name="readOnly">true</property>  
  43.     </user>  
  44.     <!-- <cluster> <node name="cobar1"> <property name="host">127.0.0.1</property>   
  45.         <property name="weight">1</property> </node> </cluster> -->  
  46.     <!-- <quarantine> <host name="1.2.3.4"> <property name="user">test</property>   
  47.         </host> </quarantine> -->  
  48.   
  49. </mycat:server>  

Schema.xml


windows下配置mycat,实现mysql数据库的读写分离!

[html] view plain copy
  1. <img src="https://img-blog.****.net/20151225113842352?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQv/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center" alt="" />  
[html] view plain copy
  1. <?xml version="1.0"?>  
  2. <!DOCTYPE mycat:schema SYSTEM "schema.dtd">  
  3. <mycat:schema xmlns:mycat="http://org.opencloudb/">  
  4.   
  5.     <schema name="TESTDB" checkSQLschema="false" sqlMaxLimit="100">  
  6.         <!-- auto sharding by id (long) -->  
  7.         <table name="travelrecord" dataNode="dn1,dn2,dn3" rule="auto-sharding-long" ruleRequired="false" />  
  8.   
  9.         <table name="test1_0" dataNode="dn1,dn2,dn3" rule="auto-sharding-long" ruleRequired="false" />  
  10.   
  11.         <!-- global table is auto cloned to all defined data nodes ,so can join   
  12.             with any table whose sharding node is in the same data node -->  
  13.         <table name="company" primaryKey="ID" dataNode="dn1,dn2,dn3" rule="mod-long"/>  
  14.         <table name="goods" primaryKey="ID" type="global" dataNode="dn1,dn2" />  
  15.   
  16.         <!-- random sharding using mod sharind rule -->  
  17.         <table name="hotnews" primaryKey="ID" dataNode="dn1,dn2,dn3"  
  18.             rule="mod-long" />  
  19.             <!--  
  20.         <table name="worker" primaryKey="ID" dataNode="jdbc_dn1,jdbc_dn2,jdbc_dn3" rule="mod-long" /> 
  21.  -->  
  22.         <table name="employee" primaryKey="ID" dataNode="dn1,dn2"  
  23.             rule="sharding-by-intfile" >  
  24.             <childTable name="childtest" primaryKey="ID" joinKey="parent_id" parentKey="id"/>  
  25.                </table>   
  26.         <table name="customer" primaryKey="ID" dataNode="dn1,dn2"  
  27.             rule="sharding-by-intfile">  
  28.             <childTable name="orders" primaryKey="ID" joinKey="customer_id"  
  29.                 parentKey="id">  
  30.                 <childTable name="order_items" joinKey="order_id"  
  31.                     parentKey="id" />  
  32.             </childTable>  
  33.             <childTable name="customer_addr" primaryKey="ID" joinKey="customer_id"  
  34.                 parentKey="id" />  
  35.         </table>  
  36.     </schema>  
  37.   
  38.     <dataNode name="dn1" dataHost="192.168.37.9" database="db1" />  
  39.     <dataNode name="dn2" dataHost="192.168.37.9" database="db2" />  
  40.     <dataNode name="dn3" dataHost="192.168.37.9" database="db3" />  
  41.   
  42.     <dataHost name="192.168.37.9" maxCon="1000" minCon="10" balance="0"  
  43.         writeType="0" dbType="mysql" dbDriver="native">  
  44.         <heartbeat>select user()</heartbeat>  
  45.         <!-- can have multi write hosts -->  
  46.         <writeHost host="hostM1" url="192.168.37.9:3306" user="root"  
  47.             password="zhangxin">  
  48.         </writeHost>  
  49.     </dataHost>  
  50. </mycat:schema>  

启动mycat


windows下配置mycat,实现mysql数据库的读写分离!

启动mysql客户端:


windows下配置mycat,实现mysql数据库的读写分离!

查看employee表信息:


windows下配置mycat,实现mysql数据库的读写分离!


重点说明:在配置的过程中需要把连接MySQL的驱动包放到mycat的lib下面