当前位置:网站首页>MyCat配置文件
MyCat配置文件
2022-08-05 05:25:00 【技术的搬运工】
1)MyCat 配置文件简介
Mycat的架构其实很好理解,Mycat是代理,Mycat后面就是物理数据库。和 Web 服务器的 Nginx 类似。
对于使用者来说,访问的都是Mycat,不会接触到后端的数据库。我们现在做一个主从、读写分离。
结构如下图:
Mycat 的配置文件都在 conf 目录里面,
这里介绍下面几个常用的配置文件 server.xml、schema.xml、rule.xml
1. server.xml
进入到 mycat 的 conf 目录查看 server.xml 文件:
使用 cat 命令查看 server.xml 文件内容
<user name="root">
<property name="password">user</property>
<property name="schemas">user</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>
<user>
<property name="password">user</property>
<property name="schemas">TESTDB</property>
<property name="readonly">true</property>
</user>
1)配置 MyCat 服务信息
如:Mycat 中的用户,用户可以访问的逻辑库,可以访问的逻辑表,服务的端口号等
标签 | 释义 |
---|---|
user | 用户配置节点 |
name | 登录的用户名,也就是连接MyCat的用户名 |
password | 登录的密码,也就是连接MyCat的密码 |
schemas | 逻辑库名,这里会和schema.xml中的配置关联,多个用逗号分开, 例如需要这个用户管理两个数据库db1, db2,则配置db1, db2 |
privileges | 配置用户针对表的增删改查的权限 |
默认配置了一个账号root密码是123456,针对数据库TESTDB,读写权限都有,没有针对表做任何特殊的权限。
2)配置权限
权限 | 内容 | 权限码 |
---|---|---|
dml | Insert、update、select、delete | 0000 |
dml权限顺序为:insert(新增),update(修改),select(查询),delete(删除),0000--> 1111,0为禁止权限,1为开启权限。
2. schema.xml
使用 cat 命令查看 schema.xml 文件
schema.xml 是 最主要的 配置文件,首先看 默认的 配置文件
<?xml version="1.0"?><!DOCTYPE mycat:schema SYSTEM "schema.dtd"><mycat:schema xmlns:mycat="http://io.mycat/"><schema name="TESTDB" checkSQLschema="false" sqlMaxLimit="100"><table name="t_user" dataNode="dn1,dn2,dn3" rule="crc32slot" /></schema><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="root"><readHost host="hostS2" url="192.168.1.200:3306" user="root" password="root" /></writeHost></dataHost></mycat:schema>
1)用于定义 逻辑库 和 逻辑表 的配置文件
在配置文件中可以定义读写分离,逻辑库,逻辑表,dataHost,dataNode 等信息
标签 | 释义 |
---|---|
schema | 配置逻辑库,name与server.xml中schema对应 |
dataNode | 定义数据节点的标签,也就是分库相关配置 |
dataHost | 物理数据库,真正存储数据的数据库 |
3. rule.xml
用于定义分片规则的配置文件.
mycat 默认的分片规则: 以500万为单位,实现分片规则.
逻辑库A 对应 dataNode-db1 和 db2.
1-500万保存在db1中, 500万零1到1000万保存在db2中,1000万零1到1500万保存在db1中.依次类推.
<tableRule name="rule1">
<rule>
<column>id</column>
<algorithm>func1</algorithm>
</rule>
</tableRule>
1)tableRule
标签 | 释义 |
---|---|
name | 属性指定唯一的名字,用于标识不同的分片规则。内嵌的rule标签则指定对物理表中的哪一列进行拆分和使用什么分片算法 |
columns | 指定要拆分的列名字 |
algorithm | 使用function标签中的name属性。连接表规则和具体分片算法。table标签内使用。让逻辑表使用这个规则进行分片 |
2)function
<function name="func1" class="io.mycat.route.function.partitionByLong">
<property name="partitionCount">8</property>
<property name="partitionLength">128</property>
</function>
边栏推荐
- Native JS takes you to understand the implementation and use of array methods
- Difference between link and @improt
- Pytorch分布式并行处理
- Come, come, let you understand how Cocos Creator reads and writes JSON files
- Collision, character controller, Cloth components (cloth), joints in the Unity physics engine
- scikit-image image processing notes
- numpy.random使用文档
- Email management Filter emails
- docker部署完mysql无法连接
- product learning materials
猜你喜欢
系统基础-学习笔记(一些命令记录)
LeetCode练习及自己理解记录(1)
人人AI(吴恩达系列)
cs231n learning record
LaTeX image captioning text column automatic line wrapping
HelloWorld
scikit-image图像处理笔记
In-depth analysis if according to data authority @datascope (annotation + AOP + dynamic sql splicing) [step by step, with analysis process]
The cocos interview answers you are looking for are all here!
NB-IOT智能云家具项目系列实站
随机推荐
LeetCode中常用语言的一些基本方法记录
Network Protocol Fundamentals - Study Notes
UI刘海屏适配方式
农场游戏果园系统+牧场养殖系统+广告联盟模式流量主游戏小程序APP V1
The cocos interview answers you are looking for are all here!
Met with the browser page
Chengyun Technology was invited to attend the 2022 Alibaba Cloud Partner Conference and won the "Gathering Strength and Going Far" Award
el-autocomplete use
HelloWorld
Native JS takes you to understand the implementation and use of array methods
关于Antd的Affix突然不好用了,或者Window的scroll监听不好用了
Matplotlib plotting notes
Passing parameters in multiple threads
【FAQ】CCAPI兼容EOS相机列表(2022年8月 更新)
Come, come, let you understand how Cocos Creator reads and writes JSON files
el-progress implements different colors of the progress bar
reduce()方法的学习和整理
Alibaba Cloud Video on Demand
Media query, rem mobile terminal adaptation
From "dual card dual standby" to "dual communication", vivo took the lead in promoting the implementation of the DSDA architecture