1. Download the Mycat service package

Wget tar ZXVF - http://dl.mycat.org.cn/1.6.7.6/20210303094759/Mycat-server-1.6.7.6-release-20210303094759-linux.tar.gz Mycat - server - 1.6.7.6 - release - 20210303094759 - Linux. Tar. GzCopy the code

2. Configure Mycat

1. Server. XML system configuration information 2. Schema. XML logical library, logical table, table sharding rules, data source 3Copy the code

server.xml

<user name="root"> <property name="password">123456</property> <property name="schemas">imall,gupao</property> </user>Copy the code

schema.xml

<schema name="imall" checkSQLschema="false" sqlMaxLimit="100"> <table name="customer" primaryKey="id" dataNode="122-imall,123-imall,124-imall" rule="auto-sharding-long" /> <table name="order_info" dataNode="122-imall,123-imall,124-imall" rule="mod-long-order"> <childTable name="order_detail" primaryKey="id" joinKey="order_id" parentKey="order_id"> </childTable> </table> </schema> <schema name="gupao" checkSQLschema="false" sqlMaxLimit="100"> <table name="student" primaryKey="sid" dataNode="122-gupao,123-gupao,124-gupao" rule="mod-long" /> <! <table name="noshard" primaryKey=" ID "autoIncrement="true" dataNode="122-gupao" /> <! --> <table name="dict" primaryKey="id" type="global" dataNode="122-gupao,123-gupao,124-gupao" / > <! <table name="fee" primaryKey=" ID "subTables="fee2025$1-3" dataNode="122-gupao" rule="sharding-by-month" /> </schema> <dataNode name="122-imall" dataHost="host122" database="imall" /> <dataNode name="123-imall" dataHost="host123" database="imall" /> <dataNode name="124-imall" dataHost="host124" database="imall" /> <dataNode name="122-gupao" dataHost="host122" database="gupao" /> <dataNode name="123-gupao" dataHost="host123" database="gupao" /> <dataNode name="124-gupao" dataHost="host124" database="gupao" /> <dataHost name="host122" maxCon="1000" minCon="10" balance="0" writeType="0" dbType="mysql" dbDriver="jdbc" switchType="1" slaveThreshold="100"> <heartbeat>select user()</heartbeat> <writeHost host="hostM1" url="jdbc:mysql://host1:3306" user="root" password="123456"> </writeHost> </dataHost> <dataHost name="host123" maxCon="1000" minCon="10" balance="0" writeType="0"  dbType="mysql" dbDriver="jdbc" switchType="1" slaveThreshold="100"> <heartbeat>select user()</heartbeat> <writeHost host="hostM1" url="jdbc:mysql://host2:3306" user="root" password="123456"> </writeHost> </dataHost> <dataHost name="host124" maxCon="1000" minCon="10" balance="0" writeType="0" dbType="mysql" dbDriver="jdbc" switchType="1" slaveThreshold="100"> <heartbeat>select user()</heartbeat> <! -- can have multi write hosts --> <writeHost host="hostM1" url="jdbc:mysql://host3:3306" user="root" password="123456"> </writeHost> </dataHost>Copy the code

The new rule. The XML

<tableRule name="mod-long-order">
        <rule>
                <columns>order_id</columns>
                <algorithm>mod-long</algorithm>
        </rule>
</tableRule>
Copy the code

Mycat service started successfully!

Mycat’s default access port is 8066. After creating two instances of imall and gupao on 122,123,124, and adding the table, After configuring imall and Gupao in mycat’s schema. XML file, and configuring root’s schema permission in server. XML, you can log in to Mycat through port 8066 as if you were logging in to mysql. You can see the two schemas configured.