• Mycat 配置 笔记


    下载 mycat 以及 jdk

        配置数据库节点,实例如下

     1 <?xml version="1.0"?>
     2 <!DOCTYPE mycat:schema SYSTEM "schema.dtd">
     3 <mycat:schema xmlns:mycat="http://io.mycat/">
     4 
     5     <!--<schema name="TESTDB" checkSQLschema="false" sqlMaxLimit="100">-->
     6 
     7          <!--<table name="travelrecord" dataNode="dn1,dn2" rule="auto-sharding-long" />-->
     8         
     9        <!-- <table name="test1_0" dataNode="dn1,dn2,dn3" rule="auto-sharding-long" ruleRequired="false" />
    10 
    11         <table name="company" primaryKey="ID" type="global" dataNode="dn1,dn2,dn3" rule="mod-long" />
    12         <table name="goods" primaryKey="ID" type="global" dataNode="dn1,dn2" />
    13         
    14         <table name="hotnews" primaryKey="ID" dataNode="dn1,dn2,dn3" rule="mod-long" />
    15         
    16         <table name="employee" primaryKey="ID" dataNode="dn1,dn2"  rule="sharding-by-intfile" />
    17         
    18         <table name="customer" primaryKey="ID" dataNode="dn1,dn2"   rule="sharding-by-intfile">
    19             <childTable name="orders" primaryKey="ID" joinKey="customer_id"
    20                         parentKey="id">
    21                 <childTable name="order_items" joinKey="order_id"
    22                             parentKey="id" />
    23             </childTable>
    24             <childTable name="customer_addr" primaryKey="ID" joinKey="customer_id"
    25                         parentKey="id" />
    26         </table>
    27     </schema>
    28     
    29     <dataNode name="dn1" dataHost="localhost1" database="db1" />
    30     <dataNode name="dn2" dataHost="localhost2" database="db2" />
    31     <dataNode name="dn3" dataHost="localhost2" database="db3" />
    32     <dataHost name="localhost1" maxCon="1000" minCon="10" balance="0"
    33               writeType="0" dbType="mysql" dbDriver="native" >
    34         <heartbeat>select user()</heartbeat>
    35         <writeHost host="hostM1" url="127.0.0.1:3306" user="root"
    36                    password="130139">
    37         </writeHost>
    38     </dataHost>
    39     
    40     
    41     <dataHost name="localhost2" maxCon="1000" minCon="10" balance="0"
    42               writeType="0" dbType="mysql" dbDriver="native" >
    43         <heartbeat>select user()</heartbeat>
    44         <writeHost host="hostM1" url="192.168.3.250:3306" user="root"
    45                    password="130139">
    46         </writeHost>
    47     </dataHost>-->
    48     
    49     
    50     <schema name="TESTDB" checkSQLschema="false" sqlMaxLimit="100">
    51                 <!-- 垂直切分 -->
    52                 <table name="test1" primaryKey="id" type="global" dataNode="nodeTest1" >
    53                 </table>
    54                 <table name="test2" primaryKey="id" type="global" dataNode="nodeTest2" >
    55                 </table>
    56 
    57                 <!-- 全局表的配置如下(比如配置文件的数据,数据不大很少变动的,但是经常用到查询的) -->
    58                 <!-- <table name="t_area" primaryKey="id" type="global" dataNode="dn1,dn2" /> -->
    59 
    60                 <!-- 水平切分 -->
    61                 <!-- ER分片表:如user表和user_detail表的关联字段user_id;保证相同user_id的数据在同一块片区上 -->
    62                 <table name="user" primaryKey="user_id" dataNode="nodeUser01,nodeUser02" rule="mod-long">
    63                     <childTable name="user_detail" primaryKey="id" joinKey="user_id" parentKey="user_id">
    64                     </childTable>
    65                 </table>
    66     </schema>
    67 
    68 
    69 
    70 
    71          <dataNode name="nodeUser01" dataHost="dataHost01" database="db3" />
    72          <dataNode name="nodeUser02" dataHost="dataHost02" database="db3" />
    73 
    74          <dataNode name="nodeTest1" dataHost="dataHost01" database="db1" />
    75          <dataNode name="nodeTest2" dataHost="dataHost02" database="db1" />
    76 
    77 
    78 
    79         <dataHost name="dataHost01" maxCon="1000" minCon="10" balance="0" writeType="0" dbType="mysql" dbDriver="native">
    80                 <heartbeat>select user()</heartbeat>
    81                 <writeHost host="hostM1" url="127.0.0.1:3306" user="root" password="130139"/>
    82         </dataHost>
    83 
    84         <dataHost name="dataHost02" maxCon="1000" minCon="10" balance="0" writeType="0" dbType="mysql" dbDriver="native">
    85                 <heartbeat>select user()</heartbeat>
    86                 <writeHost host="hostM1" url="192.168.3.250:3306" user="root" password="130139"/>
    87         </dataHost>
    88 
    89 </mycat:schema>

    配置节点中建议参考官方文档   http://www.mycat.io/document/mycat-definitive-guide.pdf  可以少走弯路

            这里重点配置JDK安装的路径     就是此处       

        这个文件重点配置它们的分片规则

        这个文件则主要是设定逻辑数据库即   127.0.0.1:8066  的数据库名称,用户名以及密码

    示例如下

      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://io.mycat/">
     12     <system>
     13     <property name="defaultSqlParser">druidparser</property>
     14     <!--<property name="useSqlStat">0</property>-->  <!-- 1为开启实时统计、0为关闭 -->
     15     <!--<property name="useGlobleTableCheck">0</property>-->  <!-- 1为开启全加班一致性检测、0为关闭 -->
     16 
     17         <!--<property name="sequnceHandlerType">2</property>-->
     18       <!--  <property name="useCompression">1</property>--> <!--1为开启mysql压缩协议-->
     19         <!--  <property name="fakeMySQLVersion">5.6.20</property>--> <!--设置模拟的MySQL版本号-->
     20     <!-- <property name="processorBufferChunk">40960</property> -->
     21     <!-- 
     22     <property name="processors">1</property> 
     23     <property name="processorExecutor">32</property> 
     24      -->
     25         <!--默认为type 0: DirectByteBufferPool | type 1 ByteBufferArena-->
     26         <!--<property name="processorBufferPoolType">0</property>-->
     27         <!--默认是65535 64K 用于sql解析时最大文本长度 -->
     28         <!--<property name="maxStringLiteralLength">65535</property>-->
     29         <!--<property name="sequnceHandlerType">0</property>-->
     30         <!--<property name="backSocketNoDelay">1</property>-->
     31         <!--<property name="frontSocketNoDelay">1</property>-->
     32         <!--<property name="processorExecutor">16</property>-->
     33         <!--
     34             <property name="serverPort">8066</property> <property name="managerPort">9066</property> 
     35             <property name="idleTimeout">300000</property> <property name="bindIp">0.0.0.0</property> 
     36             <property name="frontWriteQueueSize">4096</property> <property name="processors">32</property> -->
     37         <!--分布式事务开关,0为不过滤分布式事务,1为过滤分布式事务(如果分布式事务内只涉及全局表,则不过滤),2为不过滤分布式事务,但是记录分布式事务日志-->
     38         <!--<property name="handleDistributedTransactions">0</property>-->
     39         
     40             <!--
     41             off heap for merge/order/group/limit      1开启   0关闭
     42         -->
     43         <!--<property name="useOffHeapForMerge">1</property>-->
     44 
     45         <!--
     46             单位为m
     47         -->
     48         <!--<property name="memoryPageSize">1m</property>-->
     49 
     50         <!--
     51             单位为k
     52         -->
     53         <!--<property name="spillsFileBufferSize">1k</property>-->
     54 
     55         <!--<property name="useStreamOutput">0</property>-->
     56 
     57         <!--
     58             单位为m
     59         -->
     60         <!--<property name="systemReserveMemorySize">384m</property>-->
     61 
     62 
     63         <!--是否采用zookeeper协调切换  -->
     64         <!--<property name="useZKSwitch">true</property>-->
     65 
     66 
     67     </system>
     68     
     69     <!-- 全局SQL防火墙设置 -->
     70     <!-- 
     71     <firewall> 
     72        <whitehost>
     73           <host host="127.0.0.1" user="mycat"/>
     74           <host host="127.0.0.2" user="mycat"/>
     75        </whitehost>
     76        <blacklist check="false">
     77        </blacklist>
     78     </firewall>
     79     -->
     80     
     81     <user name="root">
     82         <property name="password">130139</property>
     83         <property name="schemas">TESTDB</property>
     84         
     85         <!-- 表级 DML 权限设置 -->
     86         <!--         
     87         <privileges check="false">
     88             <schema name="TESTDB" dml="0110" >
     89                 <table name="tb01" dml="0000"></table>
     90                 <table name="tb02" dml="1111"></table>
     91             </schema>
     92         </privileges>        
     93          -->
     94     </user>
     95 
     96     <user name="user">
     97         <property name="password">user</property>
     98         <property name="schemas">TESTDB</property>
     99         <property name="readOnly">true</property>
    100     </user>
    101 
    102 </mycat:server>

    mycat    install    安装

    mycat    start      开启

    mycat    stop      停止

    配置文件修改后,需要重启   mycat

    记录点参考网址    https://blog.csdn.net/leipeng321123/article/details/50401376

                                 https://www.cnblogs.com/parryyang/p/5758087.html

                                 https://www.cnblogs.com/rangle/archive/2018/01/02/8176362.html

                                 https://blog.csdn.net/qiaoshuai0920/article/details/52346332

    另外,一定要看官方文档     http://www.mycat.io/document/mycat-definitive-guide.pdf  

  • 相关阅读:
    bzoj1066: [SCOI2007]蜥蜴(最大流)
    bzoj4551: [Tjoi2016&Heoi2016]树(树链剖分)
    bzoj2663: [Beijing wc2012]灵魂宝石(二分+匈牙利)
    bzoj2150: 部落战争(匈牙利)
    bzoj1797: [Ahoi2009]Mincut 最小割(最小割+强联通tarjan)
    bzoj3993: [SDOI2015]星际战争(网络流)
    bzoj3504: [Cqoi2014]危桥(网络流)
    bzoj3212: Pku3468 A Simple Problem with Integers(线段树)
    bzoj4590: [Shoi2015]自动刷题机(二分答案)
    [WC2013]糖果公园
  • 原文地址:https://www.cnblogs.com/cwmizlp/p/9419420.html
Copyright © 2020-2023  润新知