使用Mycat垂直拆分,以下圖所示:php
ip | 實例 | 數據庫 |
---|---|---|
192.168.11.131 | Mycat | TESTDB |
192.168.11.133 | mysql | orders |
192.168.11.239 | mysql | products |
products.product
表數據以下:mysql
+----+--------------+
| id | product_name |
+----+--------------+
| 1 | iphone X |
| 2 | Hua Wei P20 |
| 3 | xiaomi 8 |
+----+--------------+
複製代碼
orders.order
表數據以下:sql
+----+--------------+-----+---------+
| id | product_name | num | price |
+----+--------------+-----+---------+
| 1 | iphone X | 1 | 1000000 |
| 2 | HW p20 | 1 | 400000 |
| 3 | xiaomi 8 | 1 | 200000 |
+----+--------------+-----+---------+
複製代碼
server.xml
配置系統變量和用戶權限<user name="root" defaultAccount="true">
<property name="password">123456</property>
<property name="schemas">TESTDB</property>
</user>
複製代碼
schema.xml
配置邏輯庫,內容以下:<?xml version="1.0"?>
<!DOCTYPE mycat:schema SYSTEM "schema.dtd">
<mycat:schema xmlns:mycat="http://io.mycat/">
<!-- 邏輯庫 -->
<schema name="TESTDB" checkSQLschema="false" sqlMaxLimit="100">
<table name="order" primaryKey="id" dataNode="dn1" />
<table name="product" primaryKey="id" dataNode="dn2" />
</schema>
<!-- 數據節點 -->
<dataNode name="dn1" dataHost="localhost1" database="orders"/>
<dataNode name="dn2" dataHost="localhost2" database="products"/>
<!-- 物理主機 -->
<dataHost name="localhost1" maxCon="1000" minCon="10" balance="0" writeType="0" dbType="mysql" dbDriver="native">
<heartbeat>select user()</heartbeat>
<writeHost host="order" url="192.168.11.133:3306" user="root" password="123456" />
</dataHost>
<dataHost name="localhost2" maxCon="1000" minCon="10" balance="0" writeType="0" dbType="mysql" dbDriver="native">
<heartbeat>select user()</heartbeat>
<writeHost host="product" url="192.168.11.239:3306" user="root" password="123456" />
</dataHost>
</mycat:schema>
複製代碼
# 登錄Mycat
mysql -uroot -p123456 -P8066 -h 192.168.11.131
use TESTDB;
select * from `order`;
select * from product;
複製代碼