Mycat 运行与基础操作1

2021-12-03 20:16:29 浏览数 (2)

前言

Mycat 是一个数据库分库分表中间件

这里使用最简单的取模分片作为示例,简单分享一下 Mycat 的运行与基础操作

详细内容可以参考 官方文档Mycat-ServerGet Start

Tip: 当前的最新版本为 Mycat server 1.5 GA


概要


配置

以下是关键配置

代码语言:javascript复制
--[server.xml]--------
	<user name="cc">
		<property name="password">cc</property>
		<property name="schemas">cctest</property>
	</user>
--[schema.xml]--------
	<schema name="cctest" checkSQLschema="false" sqlMaxLimit="100">
	        <table name="catworld"  dataNode="sd1,sd2,sd3"  rule="mod-long" />
	        <table name="catworld4"  dataNode="sd1,sd2,sd3,sd4"  rule="mod4-long" />
	</schema>
	...
	...
	<dataNode name="sd1" dataHost="h101" database="my1" />
	<dataNode name="sd2" dataHost="h101" database="my2" />
	<dataNode name="sd3" dataHost="h101" database="my3" />
	<dataNode name="sd4" dataHost="h202" database="my4" />
	...
	...
	<dataHost name="h101" maxCon="100" minCon="10" balance="0" writeType="0" dbType="mysql" dbDriver="native" switchType="1"  slaveThreshold="100">
		<heartbeat>select user()</heartbeat>
		<writeHost host="h101M1" url="192.168.100.101:3306" user="root" password="mysql">
		<!-- can have multi read hosts -->
		</writeHost>
	</dataHost>
	<dataHost name="h202" maxCon="100" minCon="10" balance="0" writeType="0" dbType="mysql" dbDriver="native" switchType="1"  slaveThreshold="100">
		<heartbeat>select user()</heartbeat>
		<writeHost host="h202M1" url="192.168.100.202:3306" user="root" password="mysql">
		<!-- can have multi read hosts -->
		</writeHost>
	</dataHost>
--[rule.xml]--------
	<tableRule name="mod-long">
		<rule>
			<columns>id</columns>
			<algorithm>mod-long</algorithm>
		</rule>
	</tableRule>
	<tableRule name="mod4-long">
		<rule>
			<columns>id</columns>
			<algorithm>mod4-long</algorithm>
		</rule>
	</tableRule>
	...
	...
	<function name="mod-long" class="org.opencloudb.route.function.PartitionByMod">
		<!-- how many data nodes -->
		<property name="count">3</property>
	</function>
	<function name="mod4-long" class="org.opencloudb.route.function.PartitionByMod">
		<!-- how many data nodes -->
		<property name="count">4</property>
	</function>

0 人点赞