mycat初次进阶体验

ytdu9021 9年前

来自: http://blog.csdn.net/mchdba/article/details/50616527


1 安装后进入
Schema.xml配置信息如下,数据节点名称dn1、dn2、dn3:

安装完后登录测试:
mysql -utest -ptest -h127.0.0.1 -P8066 -DTESTDB

2 , 创建表

create table travelrecord (id bigint not null primary key,user_id varchar(100),traveldate DATE, fee decimal,days int);

3,录入数据

3.1插入在分片0上:
explain insert into travelrecord (id,user_id,traveldate,fee,days) values(100001,’xiaohong’,’2014-01-06’,510.5,3);
insert into travelrecord (id,user_id,traveldate,fee,days) values(100001,’xiaohong’,’2014-01-06’,510.5,3);

3.2录入在分片1上:
explain insert into travelrecord (id,user_id,traveldate,fee,days) values(8000004,’mazi’,’2014-01-06’,510.5,3);
insert into travelrecord (id,user_id,traveldate,fee,days) values(8000004,’mazi’,’2014-01-06’,510.5,3);

3.3录入在分片2上:
explain insert into travelrecord (id,user_id,traveldate,fee,days) values(10000004,’suqi’,’2014-01-06’,510.5,3);
insert into travelrecord (id,user_id,traveldate,fee,days) values(10000004,’suqi’,’2014-01-06’,510.5,3);

4,查询数据
4.1在mycat后台的db上面,路由看到是分在3个片上面,
explain select * from Travelrecord;

4.2单个数据路由分析,都在不同的datanode上:

4.3去实际的mysql上面测试,查询数据,已经分到3个分片 db1、db2、db3上面了,如下所示: