mycat安装和使用

mycat官网

http://www.mycat.io/

mycat下载

http://dl.mycat.io/

运行环境

mysql 5.6.21

mycat 1.6.7.3  win

jdk 1.8

安装配置

1)检查mysql环境

使用本机localhost服务模拟3台数据库服务器,使用user_0做实验,表结构见后面插入语句

2) 解压mycat

D:\Soft\Mycat-server-1.6.7.3-release\mycat

3)安装mycat服务

D:\Soft\Mycat-server-1.6.7.3-release\mycat\bin>mycat.bat
Usage: mycat.bat { console : start : pause : resume : stop : restart : install : remove : status }

D:\Soft\Mycat-server-1.6.7.3-release\mycat\bin>mycat.bat install
wrapper  | Mycat-server installed.

4) 配置mycat文件

server.xml  配置mycat服务器信息

schema.xml 配置表的路由信息

rule.xml  配置分片规则

5) server.xml 配置

保留默认配置,重新配置用户名和密码,和mysql一致

   <user name="root" defaultAccount="true">

        <property name="password">wmzycn</property>
        <!-- 和 schema.xml 中 schema name 配置一致  -->
        <property name="schemas">TESTDB</property>               

    </user>

    <user name="chy">

        <property name="password">wmzycn</property>
        <!-- 和 schema.xml 中 schema name 配置一致  -->
        <property name="schemas">TESTDB</property>

        <property name="readOnly">false</property>

    </user>

6)schema.xml 配置

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

	<schema name="TESTDB" checkSQLschema="true" sqlMaxLimit="100">
		<!-- rule.xml 中 mod-long 规则 -->
		<!-- user_0 表 采用机器数取余分片 -->
		<table name="user_0" dataNode="dn1,dn2,dn3" rule="mod-long" />	
	</schema>
	<!-- 配置3台服务器信息,使用本机服务不同数据库模拟3台服务器 -->
	<dataNode name="dn1" dataHost="localhost1" database="sharding_0" />
	<dataNode name="dn2" dataHost="localhost1" database="sharding_1" />
	<dataNode name="dn3" dataHost="localhost1" database="sharding_2" />
	<!-- 配置服务器的连接信息 -->
	<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="chy" password="wmzycn"></writeHost>	
	</dataHost>
	
</mycat:schema>

7) rule.xml

检查规则,确保存在 mod-long 规则  

<tableRule name="mod-long">
		<rule>
			<columns>id</columns>
			<algorithm>mod-long</algorithm>
		</rule>
</tableRule>

<function name="mod-long" class="io.mycat.route.function.PartitionByMod">
		<!-- how many data nodes -->
		<property name="count">3</property>
</function>

8) 启动mycat服务

D:\Soft\Mycat-server-1.6.7.3-release\mycat\bin>mycat.bat start
wrapper  | Starting the Mycat-server service...
wrapper  | Waiting to start...
wrapper  | Mycat-server started.

9) 检查mycat服务

D:\Soft\Mycat-server-1.6.7.3-release\mycat\bin>mycat.bat status
wrapper  | The Mycat-server Service is installed.
wrapper  |   Start Type: Automatic
wrapper  |   Interactive: No
wrapper  |   Running: Yes

10)连接mycat服务

<property name="serverPort">8066</property>
定义 mycat 的使用端口,默认值为 8066。

使用Navicat连接mycat服务

11) 插入记录

user_0 表采用机器数取余分片

INSERT into user_0(id,name) value (1,"user1");
INSERT into user_0(id,name) value (2,"user1");
INSERT into user_0(id,name) value (3,"user1");

检查3条记录分别落在3台服务器上

12) 查询mycat

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值