mycat安装及入门(windows下安装)

https://github.com/MyCATApache/Mycat-download 具体下载哪个版本以发布为准

一、安装及启动:

1.安装

切换到mycat 目录

mycat.bat install

2.启动

mycat.bat start

3.查询运行状态

mycat.bat status

4.停止服务

mycat.bat stop

二、配置文件介绍

     2.1 Mycat主要的配置文件:

 --server.xml:是Mycat服务器参数调整和用户授权的配置文件。

  --schema.xml:是逻辑库定义和表以及分片定义的配置文件。

  --rule.xml:  是分片规则的配置文件,分片规则的具体一些参数信息单独存放为文件,也在这个目录下,配
                置文件修改需要重启MyCAT。

  --log4j.xml: 日志存放在logs/log中,每天一个文件,日志的配置是在conf/log4j.xml中,根据自己的
               需要可以调整输出级别为debug,debug级别下,会输出更多的信息,方便排查问题。

  --autopartition-long.txt,partition-hash-int.txt,sequence_conf.properties,
                   sequence_db_conf.properties 分片相关的id分片规则配置文件

  --lib	    MyCAT自身的jar包或依赖的jar包的存放目录。

  --logs    MyCAT日志的存放目录。日志存放在logs/log中,每天一个文件

其中:rule.xml、schema.xml、server.xml

  

      2.2  bserver.xml配置

<system>

	<property name="defaultSqlParser">druidparser</property>

</system>

<user name="mycat">

	<property name="password">mycat</property>

	<property name="schemas">user,pay</property>

</user>

添加两个mycat逻辑库:user,pay:

 system 参数是所有的mycat参数配置,比如添加解析器:defaultSqlParser,其他类推 user 是用户参数。

2.3 schema.xml配置文件

<schema name="user" checkSQLschema="false" sqlMaxLimit="100" dataNode="user" />
<schema name="pay"  checkSQLschema="false" sqlMaxLimit="100" dataNode="pay" >
   <table name="order" dataNode="pay1,pay2" rule="rule1"/>
</schema>

<dataNode name="user" dataHost="host" database="user" />
<dataNode name="pay1" dataHost="host" database="pay1" />
<dataNode name="pay2" dataHost="host" database="pay2" />

<dataHost name="host" maxCon="1000" minCon="10" balance="0"
   writeType="0" dbType="mysql" dbDriver="native">
   <heartbeat>select 1</heartbeat>
   <!-- can have multi write hosts -->
   <writeHost host="hostM1" url="192.168.0.2:3306" user="root" password="root" />
   <writeHost host="hostM2" url="192.168.0.3:3306" user="root" password="root" />
</dataHost>

schema: 实际逻辑库的配置,user,pay分别对应两个逻辑库,多个schema代表多个逻辑库。

dataNode:逻辑库对应的分片,如果配置多个分片只需要多个dataNode即可。

dataHost:实际的物理库配置地址,可以配置多主主从等其他配置,多个dataHost代表分片对应的物理库地址,上面的

                   writeHost、readHost代表该分片是否配置多写,主从,读写分离等高级特性。

三、测试Mycat

      3.1 修改schem.xml

<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" type="global" dataNode="dn1,dn2,dn3" />
		<table name="goods" primaryKey="ID" type="global" dataNode="dn1,dn2" />
		<!-- random sharding using mod sharind rule -->
		<table name="hotnews" primaryKey="ID" autoIncrement="true" 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>

<dataHost name="localhost" 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="localhost:3306" user="root" //数据库的用户名
				   password="yutian">//数据库的密码
			<!-- 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>

 3.2 修改server.xml

<user name="root">
		<property name="password">yutian</property>
		<property name="schemas">TESTDB</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 name="user">
		<property name="password">user</property>
		<property name="schemas">TESTDB</property>
		<property name="readOnly">true</property>
	</user>

3.2 连接Mycat

mysql -uroot -pyutian -P8066

3.3 查看库表

mysql>  show databases;
+----------+
| DATABASE |
+----------+
| TESTDB   |
+----------+
1 row in set (0.11 sec)

mysql> use TESTDB;
Database changed
mysql> show tables;
+------------------+
| Tables in TESTDB |
+------------------+
| company          |
| customer         |
| customer_addr    |
| employee         |
| goods            |
| hotnews          |
| orders           |
| order_items      |
| travelrecord     |
+------------------+
9 rows in set (0.10 sec)

mysql>

说明Mycat安装成功

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值