macat安装

1. 下载mycat

官方网站:

http://www.mycat.org.cn/

github地址

https://github.com/MyCATApache

2. Mycat安装

第一步:把MyCat的压缩包上传到linux服务器

第二步:解压缩,得到mycat目录

第三步:进入mycat/bin,启动MyCat

启动命令:./mycat start

停止命令:./mycat stop

重启命令:./mycat restart

注意:可以使用mysql的客户端直接连接mycat服务。默认服务端口为8066

3. 

在MySQL的配置文件中my.ini [mysqld] 中增加一行

  lower_case_table_names = 1

4.   Schema.xml配置

<?xml version="1.0"?>
<!DOCTYPE mycat:schema SYSTEM "schema.dtd">
<mycat:schema xmlns:mycat="http://org.opencloudb/">
<schema name="happysunday" checkSQLschema="false" sqlMaxLimit="100">
<table name="color" primaryKey="ID" type="global" dataNode="dn1,dn2,dn3" />
<!-- buyer addr order -->
<table name="user" primaryKey="ID" dataNode="dn1,dn2,dn3" rule="sharding-by-pattern">
<childTable name="shipping" primaryKey="ID" joinKey="user_id" parentKey="id"/>
</table>
<table name="user_info" primaryKey="ID" dataNode="dn1,dn2,dn3" rule="sharding-by-pattern"/>
</schema>
<dataNode name="dn1" dataHost="localhost1" database="happysunday" />
<dataNode name="dn2" dataHost="localhost1" database="happysunday2" />
<dataNode name="dn3" dataHost="localhost1" database="happysunday3" />
<dataHost name="localhost1" maxCon="10000" minCon="10" balance="1"
writeType="0" dbType="mysql" dbDriver="native" switchType="2" slaveThreshold="100">
<!-- <heartbeat>select user()</heartbeat> -->
<heartbeat>show slave status</heartbeat>
<writeHost host="hostM1" url="127.0.0.1:3306" user="root" password="root">
<!-- can have multi read hosts -->
<readHost host="hostS1" url="192.168.200.138:3306" user="root" password="123456"/>
</writeHost>
</dataHost>
</mycat:schema>

5.配置rule.xml

<tableRule name="sharding-by-pattern">
<rule>
<columns>id</columns>
<algorithm>sharding-by-pattern</algorithm>
</rule>
</tableRule>

<function name="sharding-by-pattern" class="org.opencloudb.route.function.PartitionByPattern">
<property name="patternValue">512</property>
<property name="defaultNode">2</property>
<property name="mapFile">partition-pattern.txt</property>
</function>

5.1

partition-pattern.txt

0-127=0
128-255=1
256-512=2

chmod a+x partition-pattern.txt

6.配置server.xml

 <property name="charset">utf8</property>

<user name="test">

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

    <property name="schemas">TESTDB</property>

    <!--<property name="readOnly">true</property>-->

</user>

 7.

./mycat restart

 tail -500f /logs/wrapper.log

 tail -500f /logs/mycat.log

mysql -uroot -proot -h127.0.0.1 -P8066

show databases;
use babasport;
show tables;

 刷新sql:

原文地址:https://www.cnblogs.com/liuzhipeng/p/7258783.html