1、安装mycat,点击bin下面startup_nowrap.bat启动
2、客户端连接mycat:server.xml里面的
<!--连接mycat用户名和密码、数据库-->
<user name="test">
<property name="password">test</property>
<property name="schemas">TESTDB</property>
</user>
<user name="user">
<property name="password">user</property>
<property name="schemas">TESTDB</property>
<property name="readOnly">true</property>
</user>
端口:8066
3、全局表
<schema name="TESTDB" checkSQLschema="false" sqlMaxLimit="100">
<table name="goods_class" primaryKey="ID" type="global" dataNode="dn1,dn2,dn3" />
</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" switchType="1" slaveThreshold="100">
<heartbeat>select user()</heartbeat>
<!--写-->
<writeHost host="hostM1" url="192.168.1.251:3306" user="root"
password="123456">
</writeHost>
</dataHost>
a)连接MySQL:创建db1、db2、db3数据库
b)连接mycat:
CREATE TABLE `goods_class` (
`id` INT(11) NOT NULL AUTO_INCREMENT,
`img` VARCHAR(250) NOT NULL DEFAULT '' COMMENT '图片',
`name` VARCHAR(250) NOT NULL DEFAULT '' COMMENT '分类名称',
`is_recommend` CHAR(1) NOT NULL DEFAULT '0' COMMENT '0:不推荐 1:推荐(推荐时修改utime时间)',
`sort` INT(11) NOT NULL DEFAULT '1' COMMENT '排序字段',
PRIMARY KEY (`id`)
) ENGINE=INNODB AUTO_INCREMENT=23 DEFAULT CHARSET=utf8 COMMENT='商品分类表';
INSERT INTO goods_class (img,NAME,is_recommend,sort)VALUES('1.jpg','衣服','1',10);
INSERT INTO goods_class (img,NAME,is_recommend,sort)VALUES('2.jpg','化妆品','1',20);
INSERT INTO goods_class (img,NAME,is_recommend,sort)VALUES('3.jpg','手机','1',30);
INSERT INTO goods_class (img,NAME,is_recommend,sort)VALUES('4.jpg','电脑','1',40);
INSERT INTO goods_class (img,NAME,is_recommend,sort)VALUES('5.jpg','玩具','1',50);
c)查看mysql数据库:
db1、db2、db3数据库里面创建了goods_class 分类表,每个表里面都插入5条记录