• mycat 使用


    如果是在单机上,可以使用docker 模拟多个MySQL。

    sudo sudo docker run --name mysql -p 12345:3306 -e MYSQL_ROOT_PASSWORD=xxx -d mysql

         

    查看所有的容器,包括运行与停止的

    sudo docker ps -a

    查看运行的容器

    sudo docker ps

    筛选容器

    sudo docker ps --filter "status=exited"

    运行之前运行过,但是停止的容器

    sudo docker start e9b454ca373e  ee21a1c84c54

    创建一个测试表,如果没有表,或者没有配置,mycat启动会失败的

    CREATE TABLE `c` (
    `id` bigint(20) unsigned zerofill NOT NULL AUTO_INCREMENT,
    `a` varchar(255) CHARACTER SET utf8mb4 NOT NULL DEFAULT '' COMMENT 'sdfsdfsdf',
    `b` bigint(255) DEFAULT NULL COMMENT 'skdjflksadf',
    `c` int(255) DEFAULT NULL COMMENT 'isdfasdfsdf',
    PRIMARY KEY (`id`)
    ) ENGINE=InnoDB AUTO_INCREMENT=1012791 DEFAULT CHARSET=latin1 STATS_PERSISTENT=0

     配置账户

    登录的账号密码:

    gs@gs-virtual-machine:~/Downloads/mycat$ vim conf/server.xml

    <property name="spillsFileBufferSize">1k</property>

    <property name="useStreamOutput">0</property>

    <!--
    单位为m
    -->
    <property name="systemReserveMemorySize">384m</property>


    <!--是否采用zookeeper协调切换 -->
    <property name="useZKSwitch">true</property>


    </system>

    <!-- 全局SQL防火墙设置 -->
    <firewall>
    <whitehost>
    <host host="127.0.0.1" user="gs"/>
    </whitehost>
    <blacklist check="false">
    </blacklist>
    </firewall>

    <user name="gxsdfqs">
    <property name="password">xxxx</property>
    <property name="schemas">test</property>

    <!-- 表级 DML 权限设置 -->
    <!--
    <privileges check="false">
    <schema name="TESTDB" dml="0110" >
    <table name="tb01" dml="0000"></table>
    <table name="tb02" dml="1111"></table>
    </schema>
    </privileges>
    -->
    </user>

    </mycat:server>

       配置节点

    gs@gs-virtual-machine:~/Downloads/mycat$ vim conf/schema.xml

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

    <schema name="test" checkSQLschema="false" sqlMaxLimit="100">
    <!-- auto sharding by id (long) -->
    <!-- <table name="a" dataNode="dn1, dn2, dn3" rule="mod-long" /> -->
    <table name="b" primaryKey='id' dataNode="dn1, dn2, dn3" rule="mod-long" />
    <table name="c" primaryKey='id' dataNode="dn1, dn2, dn3" rule="mod-long" />
    <!-- <table name="oc_call" primaryKey="ID" dataNode="dn1$0-743" rule="latest-month-calldate"
    /> -->
    </schema>
    <!-- <dataNode name="dn1$0-743" dataHost="localhost1" database="db$0-743"
    /> -->
    <dataNode name="dn1" dataHost="localhost1" database="test" />
    <dataNode name="dn2" dataHost="localhost2" database="test" />
    <dataNode name="dn3" dataHost="localhost3" database="test" />
    <!--<dataNode name="dn4" dataHost="sequoiadb1" database="SAMPLE" />
    <dataNode name="jdbc_dn1" dataHost="jdbchost" database="db1" />
    <dataNode name="jdbc_dn2" dataHost="jdbchost" database="db2" />
    <dataNode name="jdbc_dn3" dataHost="jdbchost" 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>
    <!-- can have multi write hosts -->
    <writeHost host="hostM1" url="localhost:3306" user="gs"
    password="gxxxs">
    <!-- can have multi read hosts -->
    </writeHost>
    <!-- <writeHost host="hostM2" url="localhost:3316" user="root" password="123456"/> -->
    </dataHost>
    <dataHost name="localhost2" 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="hostM2" url="localhost:12306" user="gs"
    password="gxxxs">
    <!-- can have multi read hosts -->
    </writeHost>
    <!-- <writeHost host="hostM2" url="localhost:3316" user="root" password="123456"/> -->
    </dataHost>
    <dataHost name="localhost3" 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="hostM3" url="localhost:12307" user="gxxxs"
    password="gxxxs">
    <!-- can have multi read hosts -->
    </writeHost>
    <!-- <writeHost host="hostM2" url="localhost:3316" user="root" password="123456"/> -->
    </dataHost>
    <!--
    <dataHost name="sequoiadb1" maxCon="1000" minCon="1" balance="0" dbType="sequoiadb" dbDriver="jdbc">
    <heartbeat> </heartbeat>
    <writeHost host="hostM1" url="sequoiadb://1426587161.dbaas.sequoialab.net:11920/SAMPLE" user="jifeng" password="jifeng"></writeHost>
    </dataHost>

    <dataHost name="oracle1" maxCon="1000" minCon="1" balance="0" writeType="0" dbType="oracle" dbDriver="jdbc"> <heartbeat>select 1 from dual</heartbeat>
    <connectionInitSql>alter session set nls_date_format='yyyy-mm-dd hh24:mi:ss'</connectionInitSql>
    <writeHost host="hostM1" url="jdbc:oracle:thin:@127.0.0.1:1521:nange" user="base" password="123456" > </writeHost> </dataHost>

    <dataHost name="jdbchost" maxCon="1000" minCon="1" balance="0" writeType="0" dbType="mongodb" dbDriver="jdbc">
    <heartbeat>select user()</heartbeat>
    <writeHost host="hostM" url="mongodb://192.168.0.99/test" user="admin" password="123456" ></writeHost> </dataHost>

    <dataHost name="sparksql" maxCon="1000" minCon="1" balance="0" dbType="spark" dbDriver="jdbc">
    <heartbeat> </heartbeat>
    <writeHost host="hostM1" url="jdbc:hive2://feng01:10000" user="jifeng" password="jifeng"></writeHost> </dataHost> -->


    </mycat:schema>

    gs@gs-virtual-machine:~/Downloads/mycat/bin$ ls
    dataMigrate.sh init_zk_data.sh mycat rehash.sh startup_nowrap.sh wrapper-linux-ppc-64 wrapper-linux-x86-32 wrapper-linux-x86-64

    gs@gs-virtual-machine:~/Downloads/mycat/bin$ ./mycat start
    Starting Mycat-server...
    Removed stale pid file: /home/gs/Downloads/mycat/logs/mycat.pid

    查看日志:

    ~/Downloads/mycat$ tail -f logs/mycat.log

    连接

    mysql -uroot -P8066 -p

    mysql> select count(*) from test.c;
    +----------+
    | count(*) |
    +----------+
    | 4263 |
    +----------+
    1 row in set (0.01 sec)

  • 相关阅读:
    【算法学习笔记】27.动态规划 解题报告 SJTU OJ 1254 传手绢
    【算法学习笔记】26.扫描维护法 解题报告 SJTU OJ 1133 数星星
    【算法学习笔记】25.贪心法 均分纸牌问题的分析
    【算法学习笔记】24.记忆化搜索 解题报告 SJTU OJ 1002 二哥种花生
    【算法学习笔记】23.动态规划 解题报告 SJTU OJ 1280 整装待发
    【算法学习笔记】22.算法设计初步 二分查找 上下界判断
    【算法学习笔记】21.算法设计初步 求第k个数 划分法 快排法
    【算法学习笔记】20.算法设计初步 归并排序 求逆序数
    【算法学习笔记】19.算法设计初步 最大子列和问题的几种方法
    【算法学习笔记】18.暴力求解法06 隐式图搜索2 八数码问题 未启发
  • 原文地址:https://www.cnblogs.com/studyNT/p/9302234.html
Copyright © 2020-2023  润新知