【Mycat】schmea.xml配置檔案學習
1.基本環境
dn1 | localhost1 |
192.168.6.121:3306---writehost 192.168.6.121:3307---readhost 192.168.6.121:3308 |
dn2 | locahost2 |
192.168.6.120:3306---writehost 192.168.6.120:3307---readhost 192.168.6.121:3308 |
dn3 | localhost3 |
192.168.6.119:3306---writehost 192.168.6.119:3307---readhost 192.168.6.119:3308 |
2.schemal配置
-
<?xml version="1.0"?>
-
<!DOCTYPE mycat:schema SYSTEM "schema.dtd">
-
<mycat:schema xmlns:mycat="">
-
-
<schema name="TESTDB" checkSQLschema="false" sqlMaxLimit="100" dataNode="dn1"> ---預設資料節點,若新建一張表company2未在配置檔案中配置,則預設建立在dn1資料節點上(私有表)
-
<!-- auto sharding by id (long) -->
-
<table name="travelrecord" dataNode="dn1,dn2,dn3" rule="auto-sharding-long" /> ---分片表,根據對應的分片規則 分片到各個物理節點上
-
-
<!-- global table is auto cloned to all defined data nodes ,so can join
-
with any table whose sharding node is in the same data node -->
-
-
<table name="company" primaryKey="ID" type="global" dataNode="dn1,dn2,dn3" /> ---全域性表,每個節點上都有的表
-
---等同於company
-
<table name="goods" primaryKey="ID" type="global" dataNode="dn1,dn2,dn3" />
-
<!-- random sharding using mod sharind rule -->
-
<table name="hotnews" primaryKey="ID" autoIncrement="true" dataNode="dn1,dn2,dn3"
-
rule="mod-long" />
-
<!-- <table name="dual" primaryKey="ID" dataNode="dnx,dnoracle2" type="global"
-
needAddLimit="false"/> <table name="worker" primaryKey="ID" dataNode="jdbc_dn1,jdbc_dn2,jdbc_dn3"
-
rule="mod-long" /> -->
-
<table name="employee" primaryKey="ID" dataNode="dn1,dn2"
-
rule="sharding-by-intfile" />
-
<table name="customer" primaryKey="ID" dataNode="dn1,dn2"
-
rule="sharding-by-intfile">
-
<childTable name="orders" primaryKey="ID" joinKey="customer_id"
-
parentKey="id">
-
<childTable name="order_items" joinKey="order_id"
-
parentKey="id" />
-
</childTable>
-
<childTable name="customer_addr" primaryKey="ID" joinKey="customer_id"
-
parentKey="id" />
-
</table>
-
<!-- <table name="oc_call" primaryKey="ID" dataNode="dn1$0-743" rule="latest-month-calldate"
-
/> -->
-
</schema>
-
<!-- <dataNode name="dn1$0-743" dataHost="localhost1" database="db$0-743"
-
/> -->
-
<dataNode name="dn1" dataHost="localhost1" database="examdb" /> ----資料節點對應的localhost以及真實的資料庫
-
<dataNode name="dn2" dataHost="localhost2" database="examdb" />
-
<dataNode name="dn3" dataHost="localhost3" database="examdb" />
-
-
-
-
<dataHost name="localhost1" maxCon="1000" minCon="10" balance="2" ------localhosts對應的連線配置資訊
-
writeType="0" dbType="mysql" dbDriver="native" switchType="1" slaveThreshold="100">
-
<heartbeat>select user()</heartbeat>
-
<!-- can have multi write hosts -->
-
<writeHost host="hostM1" url="192.168.6.121:3306" user="root"
-
password="ESBecs00">
-
<!-- can have multi read hosts -->
-
</writeHost>
-
-
</dataHost>
-
-
-
<dataHost name="localhost2" maxCon="1000" minCon="10" balance="2"
-
writeType="0" dbType="mysql" dbDriver="native" switchType="1" slaveThreshold="100">
-
<heartbeat>select user()</heartbeat>
-
<!-- can have multi write hosts -->
-
<writeHost host="hostM1" url="192.168.6.120:3306" user="root"
-
password="ESBecs00">
-
<!-- can have multi read hosts -->
-
</writeHost>
-
-
</dataHost>
-
-
<dataHost name="localhost3" maxCon="1000" minCon="10" balance="2"
-
writeType="0" dbType="mysql" dbDriver="native" switchType="1" slaveThreshold="100">
-
<heartbeat>select user()</heartbeat>
-
<!-- can have multi write hosts -->
-
<writeHost host="hostM1" url="192.168.6.119:3306" user="root"
-
password="ESBecs00">
-
<!-- can have multi read hosts -->
-
</writeHost>
-
-
</dataHost>
- </mycat:schema>
- ......未完待續
-
mysql> select * from company; ----本應該是相同的資料,改為不同的資料是為了展示負載均衡的效果
-
+----+-------------+
-
| id | name |
-
+----+-------------+
-
| 1 | this is 119 |
-
+----+-------------+
-
1 row in set (0.01 sec)
-
-
mysql> select * from company;
-
+----+-------------+
-
| id | name |
-
+----+-------------+
-
| 1 | this is 120 |
-
+----+-------------+
-
1 row in set (0.01 sec)
-
-
mysql> select * from company;
-
+----+-------------+
-
| id | name |
-
+----+-------------+
-
| 1 | this is 121 |
-
+----+-------------+
- 1 row in set (0.00 sec)
-
mysql> select * from order2; ---分片表
-
+----+----------+---------+---------------------+
-
| ID | PROVINCE | SN | CREATE_TIME |
-
+----+----------+---------+---------------------+
-
| 2 | shanghai | 2BJ0001 | 2017-05-09 15:01:33 | ---節點2上
-
| 1 | beijing | 2BJ0001 | 2017-04-23 21:48:08 | ---節點1上
-
| 3 | tianjin | 2BJ0001 | 2017-05-09 15:01:45 |
-
+----+----------+---------+---------------------+
-
3 rows in set (0.00 sec)
-
-
mysql> select * from tt; ---私有表 節點1上
-
+------+------------+
-
| id | name |
-
+------+------------+
-
| 2 | zhangsanli |
-
| 1 | 12314 |
-
+------+------------+
-
2 rows in set (0.00 sec)
-
-
mysql> select a.*,b.* from tt a,order2 b where a.id=b.ID and b.id=2; -----2和私有表不在一個節點上,查不出來
-
Empty set (0.00 sec)
-
-
mysql> select a.*,b.* from tt a,order2 b where a.id=b.ID and b.id=1; -----1和私有表在一個節點上,所以查的出來
-
+------+-------+----+----------+---------+---------------------+
-
| id | name | ID | PROVINCE | SN | CREATE_TIME |
-
+------+-------+----+----------+---------+---------------------+
-
| 1 | 12314 | 1 | beijing | 2BJ0001 | 2017-04-23 21:48:08 |
-
+------+-------+----+----------+---------+---------------------+
- 1 row in set (0.00 sec)
-
mysql> select a.* ,b.* from order2 a,order3 b where a.id=b.id and a.id=2; --單獨都是有資料的,但是id相等的分在不同的節點上,還是不能跨節點
- Empty set (0.00 sec)
-
mysql> /*!mycat:catlet=demo.catlets.ShareJoin */ select b.sn,b.CREATE_TIME,a.CREATE_TIME from order2 a,order3 b where a.id=b.id;
-
+---------------------+----+---------+---------------------+
-
| CREATE_TIME | id | sn | CREATE_TIME |
-
+---------------------+----+---------+---------------------+
-
| 2017-04-23 21:48:08 | 1 | 2BJ0001 | 2017-05-15 14:56:35 |
-
| 2017-05-09 15:01:33 | 2 | 2BJ0001 | 2017-05-15 14:56:27 |
-
| 2017-05-15 14:52:17 | 3 | 2BJ0001 | 2017-05-15 14:56:17 |
- +---------------------+----+---------+---------------------+
全域性表的查詢有負載均衡的作用
分片表和私有表如果不在一哥節點上就聯合查不到了!
uc分片表,4101在第二個節點上act為私有表,4101在第一個節點上
select * from uc_coupon where COUPON_ID=4101 ; --單獨查,是有的
select * from act_vote_info where id=4101; ---單獨查,是有的
select a.*,b.* from uc_coupon a,act_vote_info b where a.COUPON_ID=b.id and b.id=4101 limit 1; --聯合查,查不到了,因為跨節點了!
舉例:
同理:
分片表和分片表條件資料如果不在一個節點上就聯合查不到了!
mysql> select * from order2;
+----+----------+---------+---------------------+
| ID | PROVINCE | SN | CREATE_TIME |
+----+----------+---------+---------------------+
| 2 | shanghai | 2BJ0001 | 2017-05-09 15:01:33 |
| 1 | beijing | 2BJ0001 | 2017-04-23 21:48:08 |
| 3 | tianjing | 2BJ0001 | 2017-05-15 14:52:17 |
+----+----------+---------+---------------------+
3 rows in set (0.00 sec)
mysql> select * from order3;
+----+----------+---------+---------------------+
| ID | PROVINCE | SN | CREATE_TIME |
+----+----------+---------+---------------------+
| 2 | beijing | 2BJ0001 | 2017-05-15 14:56:27 |
| 1 | tianjing | 2BJ0001 | 2017-05-15 14:56:35 |
| 3 | shanghai | 2BJ0001 | 2017-05-15 14:56:17 |
+----+----------+---------+---------------------+
3 rows in set (0.00 sec)
mysql> select * from order2;
+----+----------+---------+---------------------+
| ID | PROVINCE | SN | CREATE_TIME |
+----+----------+---------+---------------------+
| 2 | shanghai | 2BJ0001 | 2017-05-09 15:01:33 |
| 1 | beijing | 2BJ0001 | 2017-04-23 21:48:08 |
| 3 | tianjing | 2BJ0001 | 2017-05-15 14:52:17 |
+----+----------+---------+---------------------+
3 rows in set (0.00 sec)
mysql> select * from order3;
+----+----------+---------+---------------------+
| ID | PROVINCE | SN | CREATE_TIME |
+----+----------+---------+---------------------+
| 2 | beijing | 2BJ0001 | 2017-05-15 14:56:27 |
| 1 | tianjing | 2BJ0001 | 2017-05-15 14:56:35 |
| 3 | shanghai | 2BJ0001 | 2017-05-15 14:56:17 |
+----+----------+---------+---------------------+
3 rows in set (0.00 sec)
+----+----------+---------+---------------------+
| ID | PROVINCE | SN | CREATE_TIME |
+----+----------+---------+---------------------+
| 2 | shanghai | 2BJ0001 | 2017-05-09 15:01:33 |
| 1 | beijing | 2BJ0001 | 2017-04-23 21:48:08 |
| 3 | tianjing | 2BJ0001 | 2017-05-15 14:52:17 |
+----+----------+---------+---------------------+
3 rows in set (0.00 sec)
mysql> select * from order3;
+----+----------+---------+---------------------+
| ID | PROVINCE | SN | CREATE_TIME |
+----+----------+---------+---------------------+
| 2 | beijing | 2BJ0001 | 2017-05-15 14:56:27 |
| 1 | tianjing | 2BJ0001 | 2017-05-15 14:56:35 |
| 3 | shanghai | 2BJ0001 | 2017-05-15 14:56:17 |
+----+----------+---------+---------------------+
3 rows in set (0.00 sec)
解決辦法:註解,詳細用法見文件
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/29096438/viewspace-2137390/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- 【Mycat】Mycat核心開發者帶你看盡Mycat三大核心配置檔案
- MyBatis學習 之 四、MyBatis配置檔案MyBatis
- nginx學習(二):初識配置檔案Nginx
- 03.MyBatis學習-----全域性配置檔案_properties_引入外部配置檔案MyBatis
- VC++學習筆記---配置檔案(一) ini檔案和propritiesC++筆記
- Laravel 學習筆記一: 專案框架和配置檔案Laravel筆記框架
- Mycat 安裝配置
- ?從零開始學習webpack系列二(配置檔案)Web
- gch檔案學習GC
- 檔案IO的學習
- SpringBoot 基礎知識學習(二)——配置檔案多環境配置Spring Boot
- SpringBoot基礎學習(二) SpringBoot全域性配置檔案及配置檔案屬性值注入Spring Boot
- jackson學習之九:springboot整合(配置檔案)Spring Boot
- mycat配置分庫分表
- Mycat分庫分表配置
- Flink 從 0 到 1 學習 —— Flink 配置檔案詳解
- 學習Hibernate原始碼三_Hibernate中的配置檔案解析原始碼
- 【DB 2學習】檢視一個資料庫的配置檔案資料庫
- 學習Rust 檔案與 IORust
- B站java學習檔案Java
- oracle的profile檔案學習Oracle
- 【轉】UCM專案管理配置學習專案管理
- MySQL運維5-Mycat配置MySql運維
- Git配置配置檔案Git
- Mybatis 學習筆記(一)——配置檔案SqlMapConfig.xml和對映檔案Mapper.xmlMyBatis筆記SQLXMLAPP
- Java學習筆記之檔案Java筆記
- 【LINUX學習】連結檔案Linux
- 學習使用.dd.gz檔案
- Bada學習-檔案系統
- 4.26檔案上傳學習
- Linux學習之檔案操作Linux
- 來吧學學.Net Core之專案檔案簡介及配置檔案與IOC的使用
- Asp.Net Core 3.1學習-讀取、監聽json配置檔案(7)ASP.NETJSON
- Nginx學習系列三Nginx的啟動、停止、修改配置檔案後重啟Nginx
- Mycat讀寫分離配置實踐
- mysql學習筆記之快速搭建PXC叢集(Mycat分片)MySql筆記
- DVWA-檔案包含學習筆記筆記
- python學習之讀寫檔案Python