mycat基本配置简单解读

schema.xml
schema.xml是最主要的配置项
<?xml version="1.0"?>
<!DOCTYPE mycat:schema SYSTEM "schema.dtd"> 
<mycat:schema xmlns:mycat="http://io.mycat/">


<!-- 数据库配置,与server.xml中的数据库对应 -->
    <schema name="lunch" checkSQLschema="false" sqlMaxLimit="100">//数据库设置,此数据库为逻辑数据库,name与server.xml中schema对应
        name:逻辑数据库名,与server.xml中的schema对应;
        checkSQLschema:数据库前缀相关设置,建议看文档,这里暂时设为false;
        sqlMaxLimit:select 时默认的limit,避免查询全表
        <table name="lunchmenu" dataNode="dn1"  /> 
        name:表名,物理数据库中表名
        dataNode:表存储到哪些节点,多个节点用逗号分隔。节点为下文dataNode设置的name
        <table name="restaurant" dataNode="dn1"  />
        <table name="userlunch" dataNode="dn1"  />
        <table name="users" dataNode="dn1"  />
        <table name="dictionary" primaryKey="id" autoIncrement="true" dataNode="dn1,dn2"  rule="mod-long" />
        primaryKey:主键字段名,自动生成主键时需要设置
        autoIncrement:是否自增
        rule:分片规则名,具体规则下文rule详细介绍
        
    </schema>


<!-- 分片配置 -->
    <dataNode name="dn1" dataHost="test1" database="lunch" /> //分片信息,也就是分库相关配置
    name:节点名,与table中dataNode对应
    datahost:物理数据库名,与datahost中name对应
    database:物理数据库中数据库名
    <dataNode name="dn2" dataHost="test2" database="lunch" />


<!-- 物理数据库配置 -->
    <dataHost name="test1" maxCon="1000" minCon="10" balance="0"  writeType="0" dbType="mysql" dbDriver="native"> //物理数据库,真正存储数据的数据库
        name:物理数据库名,与dataNode中dataHost对应
        balance: 均衡负载的方式
        writeType: 写入方式
        dbType:数据库类型
        <heartbeat>select user();</heartbeat>
        heartbeat:心跳检测语句,注意语句结尾的分号要加。
        <writeHost host="hostM1" url="192.168.0.2:3306" user="root" password="123456">  
        </writeHost>
    </dataHost>


    <dataHost name="test2" maxCon="1000" minCon="10" balance="0" writeType="0" dbType="mysql" dbDriver="native">
        <heartbeat>select user();</heartbeat>
        <writeHost host="hostS1" url="192.168.0.3:3306" user="root" password="123456">  
        </writeHost>
    </dataHost>


</mycat:schema>


======================================================================================================================================================
server.xml
<user name="test"> //用户配置节点, name登录的用户名,也就是连接Mycat的用户名
        <property name="password">test</property>  //登录的密码,也就是连接Mycat的密码
        <property name="schemas">lunch</property>  //数据库名,这里会和schema.xml中的配置关联,多个用逗号分开,例如需要这个用户需要管理两个数据库db1,db2,则配置db1,dbs
        <property name="readOnly">false</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>

猜你喜欢

转载自blog.csdn.net/weixin_40221833/article/details/79990966
今日推荐