mycat

MYCAT
//////////////////////////////////////////// /////////
=========================================== ====================
1. Installation: Download tar.gz and decompress it into the bin directory
http://code.taobao.org/svn/openclouddb/downloads/
2. Start stop
mycat start/stop/restart/status/pause
========================================= ======================
3. Use test
========================= =======
1. Install mysql locally and start mysql
2. Create three databases in mysql
CREATE database db1;
CREATE database db2;
CREATE database db3;
3. Edit mycat/conf/schema.xml and
modify writeHost/readHost The values ​​of location, user, and password match the connection information of Mysql you used.
4. Restart mycat (the default data port is 8066, and the management port is 9066)
5. Run the command: mysql -utest -ptest -h127.0.0.1 -P8066 -DTESTDB
-utest -ptest -P8066 -DTESTDB is fixed, you can configure
JDBC in navicat and change the port 3306 in the mysql URL to 8066
The user account and authorization information for accessing MyCAT are configured in the conf/server.xml file,
while the username and password information used by MyCAT to connect to the back-end MySQL library are in conf/schema.xml. These are two completely independent systems.
6. The following operations are executed in the command line executed in 5.
According to the employee table configured in schema.xml, execute the following statement

travelrecord is sharded according to the range of ID primary key:
create travelrecord: create table travelrecord (id bigint not null primary key,user_id varchar(100), traveldate DATE, fee decimal, days int);
this ID is stored on shard 0
insert into travelrecord (id,user_id,traveldate,fee,days) values(1,'wang','2014- 01-05',510.5,3);

The company table is sharded according to the rule auto-sharding-long (primary key range)
create table company(id int not null primary key,name varchar(100));
insert into company(id,name) values(1,'hp');
insert into company(id,name) values(2,'ibm');
insert into company(id,name) values(3,'oracle') ;

The hotnews table is randomly assigned to dn1, dn2, dn3 by means of touch
create table hotnews(id int not null primary key , title varchar(400) , created_time datetime);
on shard 1 and Id is 5, then to On dn3, 5%3=2, that is, the index
insert into hotnews(id,title,created_time) values(1,'first',now()) corresponding to dn3; the

employee table is based on the rule sharding-by-intfile (div Sharding field is sharding_id) for sharding
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);
insert into employee(id,name,sharding_id) values(2, 'me',10010);
insert into employee(id,name,sharding_id) values(3, 'mycat',10000);
insert into employee(id,name,sharding_id) values(4, 'mydog',10010);

7. It is found that the employee in mycat does not have The data data is allocated to db1 according to the employee's sharding rules configured in schema.xml. db3 is not configured in the rules on db2

<!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" />

<!-- random sharding using mod sharind rule -->
<table name="hotnews" primaryKey="ID" dataNode="dn1,dn2,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>
</schema>

<dataNode name="dn1" dataHost="localhost1" database="db1" />
<dataNode name="dn2" dataHost="localhost1" database="db2" />
<dataNode name="dn3" dataHost="localhost1" 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="localhost" url="localhost:3306" user="root"
password="111111">
<!-- 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>
</mycat:schema>

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326180104&siteId=291194637