Mycat的使用

Mycat支持的命令:

  console 前台启动     start 后台启动        stop 停止

  restart 重启         status 查看状态      dump 数据导出

  mycat的默认端口号为:8066

 【mycat安装】

  1. 下载mycat     https://github.com/MyCATApache/Mycat-download
  2. cd /use/local/wulei      上传mycat到服务器
  3. 解压  tar -zxvf Mycat-server-1.4-release-20151019230038-linux.tar.gz  得到mycat文件夹
  4. tree命令查看文件结构
[root@localhost wulei]# tree mycat
mycat
├── bin
│   ├── mycat
│   ├── rehash.sh
│   ├── startup_nowrap.sh
│   ├── wrapper-linux-ppc-64
│   ├── wrapper-linux-x86-32
│   └── wrapper-linux-x86-64
├── catlet
├── conf
│   ├── autopartition-long.txt
│   ├── cacheservice.properties
│   ├── ehcache.xml
│   ├── index_to_charset.properties
│   ├── log4j.xml
│   ├── partition-hash-int.txt
│   ├── partition-range-mod.txt
│   ├── router.xml
│   ├── rule.xml
│   ├── schema.xml        分片逻辑库的配置文件
│   ├── sequence_conf.properties
│   ├── sequence_db_conf.properties
│   ├── sequence_time_conf.properties
│   ├── server.xml
│   └── wrapper.conf
├── lib
│   ├── druid-1.0.14.jar
│   ├── ehcache-core-2.6.11.jar
│   ├── guava-18.0.jar
│   ├── leveldb-0.7.jar
│   ├── leveldb-api-0.7.jar
│   ├── libwrapper-linux-ppc-64.so
│   ├── libwrapper-linux-x86-32.so
│   ├── libwrapper-linux-x86-64.so
│   ├── log4j-1.2.17.jar
│   ├── mapdb-1.0.7.jar
│   ├── mongo-java-driver-2.11.4.jar
│   ├── Mycat-server-1.4-release.jar
│   ├── sequoiadb-java-driver-1.0-20150615.070208-1.jar
│   ├── slf4j-api-1.7.12.jar
│   ├── slf4j-log4j12-1.7.12.jar
│   ├── univocity-parsers-1.5.4.jar
│   └── wrapper.jar
├── logs
└── version.txt

  5. 测试   进到bin目录启动mycat     cd mycat/bin       ./mycat start     ./mycat stop

      6. 查看配置文件 vim /usr/local/wulei/mycat/conf/schema.xml  我这里把多余的注释都删了,看起来会清爽些!

<?xml version="1.0"?>
<!DOCTYPE mycat:schema SYSTEM "schema.dtd">
<mycat:schema xmlns:mycat="http://org.opencloudb/">

    <!-- testdb:逻辑库的库名,我们程序就是连的它,这个名称也可以自定义。 -->
    <schema name="TESTDB" checkSQLschema="false" sqlMaxLimit="100">
        <!-- table:逻辑表  name:表名  dataNode:数据节点      rule:分片规则-->
        <table name="travelrecord" dataNode="dn1,dn2,dn3" rule="auto-sharding-long" />
        <!-- 全局表被自动克隆到所有已定义的数据节点,因此可以连接任何表的分片节点都在同一个数据节点中 -->
        <table name="company" primaryKey="ID" type="global" dataNode="dn1,dn2,dn3" />
        <table name="goods" primaryKey="ID" type="global" dataNode="dn1,dn2" />
        <!-- 使用mod sharind规则随机分片 -->
        <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 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>
    </schema>
    

    <!-- dataNode:数据节点    dataHost:节点主机   database:物理库库名  -->
    <dataNode name="dn1" dataHost="localhost1" database="db1" />
    <dataNode name="dn2" dataHost="localhost1" database="db2" />
    <dataNode name="dn3" dataHost="localhost1" database="db3" />
    

   <!-- 主机配置 -->
    <dataHost name="localhost1" maxCon="1000" minCon="10" balance="0"
        writeType="0" dbType="mysql" dbDriver="native" switchType="1"  slaveThreshold="100">
        <heartbeat>select user()</heartbeat>
        <!-- 主节点 -->
        <writeHost host="hostM1" url="localhost:3306" user="root"password="123456"></writeHost>
        <!-- 从节点 -->
        <writeHost host="hostS1" url="localhost:3316" user="root"
            password="123456" />
        <!-- <writeHost host="hostM2" url="localhost:3316" user="root" password="123456"/> -->
    </dataHost>
    
</mycat:schema>
扫描二维码关注公众号,回复: 3290337 查看本文章

<?xml version="1.0"?><!DOCTYPE mycat:schema SYSTEM "schema.dtd"><mycat:schema xmlns:mycat="http://org.opencloudb/">
<!-- testdb:逻辑库的库名,我们程序就是连的它,这个名称也可以自定义。 --><schema name="TESTDB" checkSQLschema="false" sqlMaxLimit="100"><!-- table:逻辑表  name:表名  dataNode:数据节点  rule:分片规则--><table name="travelrecord" dataNode="dn1,dn2,dn3" rule="auto-sharding-long" /><!-- 全局表被自动克隆到所有已定义的数据节点,因此可以连接任何表的分片节点都在同一个数据节点中 --><table name="company" primaryKey="ID" type="global" dataNode="dn1,dn2,dn3" /><table name="goods" primaryKey="ID" type="global" dataNode="dn1,dn2" /><!-- 使用mod sharind规则随机分片 --><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 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></schema><!-- dataNode:数据节点    dataHost:节点主机   database:物理库库名  --><dataNode name="dn1" dataHost="localhost1" database="db1" /><dataNode name="dn2" dataHost="localhost1" database="db2" /><dataNode name="dn3" dataHost="localhost1" database="db3" /><dataHost name="localhost1" maxCon="1000" minCon="10" balance="0"writeType="0" dbType="mysql" dbDriver="native" switchType="1"  slaveThreshold="100"><heartbeat>select user()</heartbeat><!-- 主节点 --><writeHost host="hostM1" url="localhost:3306" user="root"password="123456"></writeHost><!-- 从节点 --><writeHost host="hostS1" url="localhost:3316" user="root"password="123456" /><!-- <writeHost host="hostM2" url="localhost:3316" user="root" password="123456"/> --></dataHost></mycat:schema>

猜你喜欢

转载自www.cnblogs.com/wlwl/p/9690451.html