(04)Mycat实现分库

1、如何选择分库表

java 复制代码
#客户表  rows:20万 
CREATE TABLE customer(
    id INT AUTO_INCREMENT,
    NAME VARCHAR(200),
    PRIMARY KEY(id)
);
 
#订单表   rows:600万
CREATE TABLE orders(
    id INT AUTO_INCREMENT,
    order_type INT,
    customer_id INT,
    amount DECIMAL(10,2),
    PRIMARY KEY(id)  
); 
 
#订单详细表     rows:600万
CREATE TABLE orders_detail(
    id INT AUTO_INCREMENT,
    detail VARCHAR(2000),
    order_id INT,
    PRIMARY KEY(id)
);
 
#订单状态字典表   rows:20
CREATE TABLE dict_order_type(
    id INT AUTO_INCREMENT,
    order_type VARCHAR(200),
    PRIMARY KEY(id)
);
 
 select o.*,od.detail,d.order_type 
from orders  o 
inner join orders_detail  od on o.id =od.order_id  
 inner join dict_order_type d on o.order_type=d.id  
where o.customer_id=xxxx

2、schema.xml

java 复制代码
<mycat:schema xmlns:mycat="http://io.mycat/">
 
        <schema name="TESTDB" checkSQLschema="false" sqlMaxLimit="100" dataNode="dn1">
                <table name="customer" dataNode="dn2" ></table>
        </schema>
        <dataNode name="dn1" dataHost="host1" database="atguigu_mc" />
        <dataNode name="dn2" dataHost="host2" database="atguigu_sm" />
        <dataHost name="host1" maxCon="1000" minCon="10" balance="2"
                          writeType="0" dbType="mysql" dbDriver="native" switchType="1"  slaveThreshold="100">
                <heartbeat>select user()</heartbeat>
                <writeHost host="hostm1" url="192.168.67.1:3306" user="root"
                                   password="123123">
                       <readHost host="hosts1" url="192.168.67.131:3306" user="root"
                                   password="123123">
                       </readHost>
                </writeHost>
        </dataHost>
        <dataHost name="host2" 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.67.1:3306" user="root"
                                   password="123123">
                </writeHost>
        </dataHost>
 
</mycat:schema>
相关推荐
码河漫步8 小时前
win11下mysql数据库设置主从
数据库·mysql
wanhengidc8 小时前
云手机的硬件依赖性如何?
运维·服务器·智能手机·云计算
星浩AI8 小时前
AI 并不懂文字,它只认向量:一文搞懂 Embedding
后端
程序员博博8 小时前
这才是vibe coding正确的打开方式 - 手把手教你开发一个MCP服务
javascript·人工智能·后端
90后的晨仔8 小时前
阿里云服务器如何给子账号设置指定具体的那一台服务器?
后端
VekiSon8 小时前
Linux系统编程——标准IO
linux·运维·服务器
期待のcode9 小时前
springboot热部署
java·spring boot·后端
expect7g9 小时前
Paimon源码解读 -- FULL_COMPACTION_DELTA_COMMITS
大数据·后端·flink
Stone_OverLooking9 小时前
Qt6.5.3 mingw64 Ninja编译oracle oci驱动
数据库·qt·oracle
踏浪无痕9 小时前
周末拆解:QLExpress 如何做到不编译就能执行?
后端·算法·架构