192.168.192.157
192.168.192.158
192.168.192.159
2.在三台数据库实例中建库建表
将准备好的三个SQL脚本, 分别导入到三台MySQL实例中 ;
登录MySQL数据库之后, 使用source命令导入 ;
四、schema.xml的配置
<?xml version="1.0"?>
<!DOCTYPE mycat:schema SYSTEM "schema.dtd">
<mycat:schema xmlns:mycat="http://io.mycat/">
<schema name="ITCAST_DB" checkSQLschema="false" sqlMaxLimit="100">
<table name="tb_areas_city" dataNode="dn1" primaryKey="id" />
<table name="tb_areas_provinces" dataNode="dn1" primaryKey="id" />
<table name="tb_areas_region" dataNode="dn1" primaryKey="id" />
<table name="tb_user" dataNode="dn1" primaryKey="id" />
<table name="tb_user_address" dataNode="dn1" primaryKey="id" />
<table name="tb_goods_base" dataNode="dn2" primaryKey="id" />
<table name="tb_goods_desc" dataNode="dn2" primaryKey="goods_id" />
<table name="tb_goods_item_cat" dataNode="dn2" primaryKey="id" />
<table name="tb_order_item" dataNode="dn3" primaryKey="id" />
<table name="tb_order_master" dataNode="dn3" primaryKey="order_id" />
<table name="tb_order_pay_log" dataNode="dn3" primaryKey="out_trade_no" />
</schema>
<dataNode name="dn1" dataHost="host1" database="user_db" />
<dataNode name="dn2" dataHost="host2" database="goods_db" />
<dataNode name="dn3" dataHost="host3" database="order_db" />
<dataHost name="host1" 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.192.157:3306" user="root" password="itcast"></writeHost>
</dataHost>
<dataHost name="host1" maxCon="1000" minCon="10" balance="0" writeType="0" dbType="mysql" dbDriver="native" switchType="1" slaveThreshold="100">
<heartbeat>select user()</heartbeat>
<writeHost host="hostM2" url="192.168.192.158:3306" user="root" password="itcast"></writeHost>
</dataHost>
<dataHost name="host3" maxCon="1000" minCon="10" balance="0" writeType="0" dbType="mysql" dbDriver="native" switchType="1" slaveThreshold="100">
<heartbeat>select user()</heartbeat>
<writeHost host="hostM3" url="192.168.192.159:3306" user="root" password="itcast"></writeHost>
</dataHost>
</mycat:schema>
五、server.xml的配置
<user name="root" defaultAccount="true">
<property name="password">123456</property>
<property name="schemas">ITCAST_DB</property>
</user>
<user name="test">
<property name="password">123456</property>
<property name="schemas">ITCAST_DB</property>
</user>
<user name="user">
<property name="password">123456</property>
<property name="schemas">ITCAST_DB</property>
<property name="readOnly">true</property>
</user>
六、测试
1.查询数据
select from tb_goods_base;
select from tb_user;
select * from tb_order_master;
2.插入数据
insert into
tb_user_address(id,user_id,province_id,city_id,town_id,mobile,address,contact,is_default,notes,create_date,alias) values
(null,'java00001',NULL,NULL,NULL,'13900112222','钟楼','张三','
《一线大厂Java面试题解析+后端开发学习笔记+最新架构讲解视频+实战项目源码讲义》
【docs.qq.com/doc/DSmxTbFJ1cmN1R2dB】 完整内容开源分享
0',NULL,NULL,NULL)
insert into
tb_order_item(id,item_id,goods_id,order_id,title,price,num,total_fee,pic_path,seller_id)
values (null,19,149187842867954,3,'3G 6','1.00',5,'5.00',NULL,'qiandu')
3.测试跨分片的查询
SELECT order_id , payment ,receiver, province , city , area FROM tb_order_master o ,
tb_areas_provinces p , tb_areas_city c , tb_areas_region r
WHERE o.receiver_province = p.provinceid AND o.receiver_city = c.cityid AND
o.receiver_region = r.areaid ;
当运行上述的SQL语句时, MyCat会报错, 原因是因为当前SQL语句涉及到跨域的join操作 ;
七、全局表配置
1.数据备份
将数据节点user_db 中的关联的字典表 tb_areas_provinces , tb_areas_city , tb_areas_region中的数据备份 ;
总结
在清楚了各个大厂的面试重点之后,就能很好的提高你刷题以及面试准备的效率,接下来小编也为大家准备了最新的互联网大厂资料。
本文已被CODING开源项目:【一线大厂Java面试题解析+核心总结学习笔记+最新讲解视频+实战项目源码】收录
</div>
<div id="asideoffset"></div>
免责声明:
1. 本站所有资源来自网络搜集或用户上传,仅作为参考不担保其准确性!
2. 本站内容仅供学习和交流使用,版权归原作者所有!© 查看更多
3. 如有内容侵害到您,请联系我们尽快删除,邮箱:kf@codeae.com