欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

Windows安装配置Mycat

程序员文章站 2022-07-14 23:38:19
...

第一步,安装JDK并配置环境变量

第二步,安装MySQL

第三步,创建mycat数据库并创建user表

Windows安装配置Mycat

添加一条数据

Windows安装配置Mycat

第四步,下载Mycat

下载地址:https://github.com/MyCATApache/Mycat-download

我下载的版本是1.5

第四步,解压压缩包,最好放到没有中文路径的目录

Windows安装配置Mycat

第五步,安装mycat,使用管理员身份打开cmd,进入D:/mycat/bin目录

执行mycat.bat install命令

第六步,配置用户信息,打开conf文件夹下的server.xml

Windows安装配置Mycat

添加testuser用户,它只可以访问testmycat库

第七步,配置数据库信息,打开conf文件夹下的schema.xml

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

	<schema name="TESTDB" checkSQLschema="false" sqlMaxLimit="100">
		<!-- auto sharding by id (long) -->
		<table name="travelrecord" dataNode="dn1,dn2,dn3" rule="auto-sharding-long" />

		<!-- global table is auto cloned to all defined data nodes ,so can join 
			with any table whose sharding node is in the same data node -->
		<table name="company" primaryKey="ID" dataNode="dn3,dn2,dn1" rule="mod-long"/>
		<table name="goods" primaryKey="ID" type="global" dataNode="dn1,dn2" />
		<!-- random sharding using mod sharind rule -->
		<table name="hotnews" primaryKey="ID" dataNode="dn1,dn2,dn3"
			rule="mod-long" />
		<!-- <table name="dual" primaryKey="ID" dataNode="dnx,dnoracle2" type="global" 
			needAddLimit="false"/> <table name="worker" primaryKey="ID" dataNode="jdbc_dn1,jdbc_dn2,jdbc_dn3" 
			rule="mod-long" /> -->
		<table name="employee" primaryKey="ID" dataNode="dn1,dn2"
			rule="sharding-by-intfile" />
		<table name="customer" primaryKey="ID" dataNode="dn1,dn2"
			rule="sharding-by-intfile">
			<childTable name="orders" primaryKey="ID" joinKey="customer_id"
				parentKey="id">
				<childTable name="order_items" joinKey="order_id"
					parentKey="id" />
			</childTable>
			<childTable name="customer_addr" primaryKey="ID" joinKey="customer_id"
				parentKey="id" />
		</table>
		<!-- <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" 
		/> -->
		
	<!-- 测试 -->
	<schema name="testmycat" checkSQLschema="true" sqlMaxLimit="100">
		<table name="user" dataNode="testhost_dn1" type="global"/>
	</schema>		
	<dataNode name="dn1" dataHost="localhost1" database="db1" />
	<dataNode name="dn2" dataHost="localhost1" database="db2" />
	<dataNode name="dn3" dataHost="localhost1" database="db3" />
	<!--<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" /> -->
	<!-- 测试 -->
	<dataNode name="testhost_dn1" dataHost="testhost" database="mycat" />
	<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="10.202.4.39:3306" user="root"
			password="sf123456">
			<!-- can have multi read hosts -->
			<!--<readHost host="hostS2" url="192.168.1.200:3306" user="root" password="xxx" />-->
		</writeHost>
		<!--<writeHost host="hostS1" url="localhost:3316" user="root"-->
			<!--password="123456" />-->
		<!-- <writeHost host="hostM2" url="localhost:3316" user="root" password="123456"/> -->
	</dataHost>
	<!-- 测试 -->
	<dataHost name="testhost" 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">
			<!-- can have multi read hosts -->
			<!--<readHost host="hostS2" url="192.168.1.200:3306" user="root" password="xxx" />-->
		</writeHost>
	</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> -->

	<!-- <dataHost name="jdbchost" maxCon="1000" minCon="10" balance="0" dbType="mysql" 
		dbDriver="jdbc"> <heartbeat>select user()</heartbeat> <writeHost host="hostM1" 
		url="jdbc:mysql://localhost:3306" user="root" password="123456"> </writeHost> 
		</dataHost> -->
	
	
</mycat:schema>

添加了三个测试的schema、dataNode、dataHost标签,连接的是本地创建的mycat库,并配置user表为全局表。

注意:schema、dataNode、dataHost标签必须按照顺序写,即

schema

schema

。。。

dataNode

dataNode

。。。

dataHost

dataHost

。。。

否则启动会报错。

第八步,配置wrapper.conf 

修改jdk地址

Windows安装配置Mycat

修改jvm参数

Windows安装配置Mycat

如果是jdk8需要修改MaxPermSize为MaxMetaspaceSize,否则启动报错

第九步,启动mycat

使用管理员身份打开cmd,进入D:/mycat/bin目录

执行mycat.bat start命令

通过mycat.bat status命令查看状态

第十步,使用Navicat连接mycat

Windows安装配置Mycat

Windows安装配置Mycat

 

Windows安装配置Mycat