- 使用全局表
<table name="dict" primaryKey="did" type="global" dataNode="node1,node2,node3"/>
mycat console或mycat start
CREATE TABLE dict(
did BIGINT AUTO_INCREMENT,
title VARCHAR(50),
content TEXT ,
CONSTRAINT pk_did PRIMARY KEY(did)
)ENGINE=InnoDB AUTO_INCREMENT=0 DEFAULT CHARSET=utf8 ROW_FORMAT=DYNAMIC COMMENT='字典表';
INSERT INTO dict(title,content) VALUES ('info-a',@@hostname);
INSERT INTO dict(title,content) VALUES ('info-b',@@hostname);
INSERT INTO dict(title,content) VALUES ('info-c',@@hostname);
select * from dict;
- 增加全局区域表
CREATE TABLE area (
id INT NOT NULL PRIMARY KEY auto_increment,
NAME VARCHAR (20) NOT NULL
)ENGINE=InnoDB AUTO_INCREMENT=0 DEFAULT CHARSET=utf8 ROW_FORMAT=DYNAMIC COMMENT='区域表';
insert into area(name) values('北京');
insert into area(name) values('上海');
insert into area(name) values('广州');
insert into area(name) values('深圳');
- ER关系表
<table name="t_order" primaryKey="id" autoIncrement="true" dataNode="node1,node2,node3" rule="mod-long">
<childTable name="t_order_detail" primaryKey="id" joinKey="order_id" parentKey="id" />
</table>
CREATE TABLE `t_order` (
`id` int(11) NOT NULL PRIMARY KEY,
`sn` varchar(64) NOT NULL,
`create_time` datetime NOT NULL,
KEY `id` (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=0 DEFAULT CHARSET=utf8 ROW_FORMAT=DYNAMIC COMMENT='订单表';
CREATE TABLE `t_order_detail` (
`id` int(11) NOT NULL PRIMARY KEY,
`order_id` int(11) NOT NULL,
`address` varchar(128) NOT NULL,
`create_time` datetime NOT NULL,
KEY `fk_ordid` (`order_id`)
) ENGINE=InnoDB AUTO_INCREMENT=0 DEFAULT CHARSET=utf8 ROW_FORMAT=DYNAMIC COMMENT='订单详情表';
INSERT INTO `t_order` (id,sn,create_time) VALUES (next value for MYCATSEQ_ORDERSEQ, 'BJ0001', NOW());
INSERT INTO `t_order` (id,sn,create_time) VALUES (next value for MYCATSEQ_ORDERSEQ, 'BJ0002', NOW());
INSERT INTO `t_order` (id,sn,create_time) VALUES (next value for MYCATSEQ_ORDERSEQ, 'BJ0003', NOW());
INSERT INTO `t_order` (id,sn,create_time) VALUES (next value for MYCATSEQ_ORDERSEQ, 'BJ0004',NOW());
INSERT INTO t_order_detail(id,order_id,address,create_time) VALUES (next value for MYCATSEQ_ORDERDETAILSEQ,1,'test data of ORDER1(ID=1,BJ001) ',NOW());
INSERT INTO t_order_detail(id,order_id,address,create_time) VALUES (next value for MYCATSEQ_ORDERDETAILSEQ,2,'test data of ORDER1(ID=1,BJ002) ',NOW());
INSERT INTO t_order_detail(id,order_id,address,create_time) VALUES (next value for MYCATSEQ_ORDERDETAILSEQ,2,'test data of ORDER1(ID=1,BJ002) ',NOW());
INSERT INTO t_order_detail(id,order_id,address,create_time) VALUES (next value for MYCATSEQ_ORDERDETAILSEQ,3,'test data of ORDER1(ID=1,BJ003) ',NOW());
INSERT INTO t_order_detail(id,order_id,address,create_time) VALUES (next value for MYCATSEQ_ORDERDETAILSEQ,3,'test data of ORDER1(ID=1,BJ003) ',NOW());
INSERT INTO t_order_detail(id,order_id,address,create_time) VALUES (next value for MYCATSEQ_ORDERDETAILSEQ,4,'test data of ORDER1(ID=1,BJ004) ',NOW());
select * from t_order a join t_order_detail b on a.id = b.order_id;