Mycat垂直分库

在网站建立之初,我们多个客户终端都是直接连接数据库,大体如下

image-20200404010759017

但是随着业务量的增加,我们这个时候数据库压力也随之增加,我们的结构演变成了

image-20200404011226162

随着数据量不断增加,业务复杂度,人员的增加,这个时候我们又需要把业务分开单独数据库

image-20200405124308369

安装Mycat

​ 安装中间件,请查看教程: ​ https://www.pv3.com.cn/post/tool/mycat_install/

修改schema.xml

<?xml version="1.0"?>
<!DOCTYPE mycat:schema SYSTEM "schema.dtd">
<mycat:schema xmlns:mycat="http://io.mycat/">
       <schema name="TEST" checkSQLschema="false" sqlMaxLimit="100">
            <table name="user" primaryKey="id" dataNode="dn1" />
            <table name="city" primaryKey="id" dataNode="dn2" />
       </schema>
       <dataNode name="dn1" dataHost="sulwan" database="test" />
       <dataNode name="dn2" dataHost="sulwan2" database="edu" />
        <dataHost name="sulwan" maxCon="500" minCon="20" balance="0"
                writeType="0" dbType="mysql" dbDriver="native" switchType="1" slaveThreshold="100">
                <heartbeat>select user()</heartbeat>
                <writeHost host="sulwan10" url="192.168.168.10:3306" user="root" password="123456" >
                        <readHost host="sulwan11" url="192.168.168.11:3306" user="root" password="123456"/>
                </writeHost>
        </dataHost>
        <dataHost name="sulwan2" maxCon="500" minCon="20" balance="0"
                writeType="0" dbType="mysql" dbDriver="native" switchType="1" slaveThreshold="100">
                <heartbeat>select user()</heartbeat>
                <writeHost host="sulwan10" url="192.168.168.10:3306" user="root" password="123456" >
                        <readHost host="sulwan11" url="192.168.168.11:3306" user="root" password="123456"/>
                </writeHost>
        </dataHost>
</mycat:schema>

配置就是这么简单,多个库整合成一个虚拟库!