0 mycat安装

来源:互联网 发布:初级程序员考试考点 编辑:程序博客网 时间:2024/05/17 02:11

一:下载jdk1.7

        Mycat-server-1.2-GA-win(windows版的mycat)

       mysql5.1.62

      

         安装jdk不要有空格。在mysql中创建3个数据库caeate database  db1。然后db2 db3.

二:mycat的主要配置文件有三个:

       1:wrapper.conf,配置启动相关的参数。

        2:server.xml配置mycat作为服务,需要的自身参数。

        3:schema.xml配置最多的,mycat连接各个数据库及策略的配置。


三:具体配置:

      1:wrapper.java.command=C:\Java7\jdk1.7.0_80\bin\java  修改这里。在文件的下面有jvm启动参数的设置。

       2:server.xml

<mycat:server xmlns:mycat="http://org.opencloudb/"><system>    <property name="sequnceHandlerType">0</property> </system><user name="test"><property name="password">test</property><property name="schemas">TESTDB</property></user></mycat:server>

这里的test和password的test是指的是到时候链接mycat的用户名和密码。


    3: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" type="global" dataNode="dn1,dn2,dn3" /><table name="goods" primaryKey="ID" type="global" dataNode="dn1,dn2,dn3" /><!-- random sharding using mod sharind rule --><table name="hotnews" primaryKey="ID" dataNode="dn1,dn2,dn3"rule="mod-long" /><!-- <table name="worker" primaryKey="ID" dataNode="jdbc_dn1,jdbc_dn2,jdbc_dn3" rule="mod-long" /> --><table name="employee" primaryKey="ID" dataNode="dn1,dn2,dn3"rule="sharding-by-intfile" /><table name="customer" primaryKey="ID" dataNode="dn1,dn2,dn3"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></schema><dataNode name="dn1" dataHost="localhost1" database="db1" /><dataNode name="dn2" dataHost="localhost1" database="db2" /><dataNode name="dn3" dataHost="localhost1" database="db3" /><!-- <dataNode name="jdbc_dn1" dataHost="jdbchost" database="db1" /><dataNode name="jdbc_dn2" dataHost="jdbchost" database="db2" /><dataNode name="jdbc_dn3" dataHost="jdbchost" database="db3" /> --><dataHost name="localhost1" maxCon="1000" minCon="10" balance="0"writeType="0" dbType="mysql" dbDriver="native"><heartbeat>select user()</heartbeat><!-- can have multi write hosts --><writeHost host="hostM1" url="localhost:3306" user="root"password="wang"><!-- can have multi read hosts --><!-- <readHost host="hostS1" url="localhost:3306" user="root" password="123456" /> --></writeHost><!-- <writeHost host="hostM2" url="localhost:3316" user="root" password="123456"/> --></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>

注意db1和db2,db3在table标签的关系。


这里每一个table标签对应一张表。

==


四:启动mycat,windows下是运行bin下的startup_nowrap.bat,有问题可以配置log4j.xml

        

log4j 2016-09-24 08:21:18 [G:\Mycat-server-1.2-GA-win/conf/log4j.xml] load completed.MyCAT Server startup successfully. see logs in logs/mycat.log

五: 

用Navicat for MySQL像mysql那样去连接mycat,端口8066、


六:执行sql,看数据库


 create table employee (id int not null primary key,name varchar(100),sharding_id int not null); insert into employee(id,name,sharding_id) values(1,'leader us',10000);

注意这里的employee是在shema.xml有配置的table名称

0 0
原创粉丝点击