SuSE涓婅繍琛孧yCat锛堜簩锛夛細閰嶇疆鍗曠偣MyCat

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了SuSE涓婅繍琛孧yCat锛堜簩锛夛細閰嶇疆鍗曠偣MyCat相关的知识,希望对你有一定的参考价值。

鏍囩锛?a href='http://www.mamicode.com/so/1/%e4%b8%8d%e5%90%8c' title='涓嶅悓'>涓嶅悓   limit   span   index   mys   update   閰嶇疆鏂囦欢   memory   缁撴瀯   

 https://www.jianshu.com/p/8848f6a802b1

 

SuSE涓婅繍琛孧yCat锛堜簩锛夛細閰嶇疆鍗曠偣MyCat

鐩爣

閫氳繃鏈枃鎿嶄綔锛屾惌寤洪潤鎬佺粨鏋勫涓嬪浘鐨勪竴涓狹yCat闆嗙兢銆備负浜嗚妭鐪佽祫婧愶紝3涓墿鐞嗗簱閮藉皢瀛樻斁鍦ㄥ悓涓€涓狹ySQL瀹炰緥褰撲腑銆?/p>

 
鎶€鏈浘鐗? src=

閮ㄧ讲mysql鑺傜偣

鍒涘缓鍒嗙墖鑺傜偣锛堝簱锛?/h3>

CREATE DATABASE mycat00;
CREATE DATABASE mycat01;
CREATE DATABASE mycat02;

CREATE TABLE mycat00.test_tbl(
id INT UNSIGNED NOT NULL PRIMARY KEY,
date DATETIME NOT NULL );
CREATE TABLE mycat01.test_tbl(
id INT UNSIGNED NOT NULL PRIMARY KEY,
date DATETIME NOT NULL );
CREATE TABLE mycat02.test_tbl(
id INT UNSIGNED NOT NULL PRIMARY KEY,
date DATETIME NOT NULL );

鍒涘缓铏氭嫙琛ㄧ敤鎴?/h3>

CREATE USER 鈥榬oot鈥?span class="token variable">@鈥?鈥?IDENTIFIED BY 鈥榬oot鈥?span class="token punctuation">;
GRANT ALL PRIVILIGES ON `mycat%`.* TO 鈥榬oot鈥?span class="token variable">@鈥?鈥?span class="token punctuation">;

鎻掑叆鍘熷鏁版嵁


INSERT INTO mycat00.test_tbl(id,date)
VALUES (0,鈥?000-01-01鈥?span class="token punctuation">);

INSERT INTO mycat01.test_tbl(id,date)
VALUES (1,鈥?000-02-01鈥?span class="token punctuation">);

INSERT INTO mycat02.test_tbl(id,date)
VALUES (2,鈥?000-03-01鈥?span class="token punctuation">);

閰嶇疆MyCat

MyCat鐨勯厤缃枃浠堕泦涓湪鍏堕厤缃枃浠跺す/usr/local/mycat/conf鍐咃紝浠ヤ笅宸ヤ綔灏嗕互璇ユ枃浠跺す涓哄熀鍑嗐€?/p>

璺敱瑙勫垯锛坮ule.xml锛?/h3>

澶囦唤鍘熸湁璺敱瑙勫垯鏂囦欢rule.xml鍚庯紝灏嗘暣涓猺ule.xml鏀瑰啓鎴愬涓嬪唴瀹癸細


<?xml version="1.0" encoding="UTF-8"?>
<!-- - - Licensed under the Apache License, Version 2.0 (the "License");
  - you may not use this file except in compliance with the License. - You
  may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0
  - - Unless required by applicable law or agreed to in writing, software -
  distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT
  WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the
  License for the specific language governing permissions and - limitations
  under the License. -->
<!DOCTYPE mycat:rule SYSTEM "rule.dtd">
<mycat:rule xmlns:mycat="http://io.mycat/">
  <tableRule name="cicular_month_rule">
    <rule>
      <columns>date</columns>
      <algorithm>cicular_month</algorithm>
    </rule>
  </tableRule>

  <function name="cicular_month"
    class="io.mycat.route.function.PartitionByMonth">
    <property name="dateFormat">yyyy-MM-dd</property>
    <property name="sBeginDate">2000-01-01</property>
    <property name="sEndDate">2000-03-01</property>
    <property name="nPartition">3</property>
  </function>
</mycat:rule>

閰嶇疆铏氭嫙搴撳強铏氭嫙琛紙schema.xml锛?/h3>

澶囦唤鍘熸湁铏氭嫙搴撴枃浠秙chema.xml鍚庯紝灏嗘暣涓猻chema.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="test_tbl" dataNode="dn00,dn01,dn02" rule="cicular_month_rule" />
  </schema>

  <dataNode name="dn00" dataHost="dh00" database="mycat00" />
  <dataNode name="dn01" dataHost="dh00" database="mycat01" />
  <dataNode name="dn02" dataHost="dh00" database="mycat02" />

  <dataHost name="dh00"
    dbType="mysql" dbDriver="native"
    maxCon="9" minCon="1" balance="0" switchType="0">
    <heartbeat>select 1</heartbeat>
    <writeHost host="host00"
      url="192.168.35.125:3306" user="root" password="root" />
  </dataHost>
</mycat:schema>

閰嶇疆MyCat鏈嶅姟淇℃伅锛坰erver.xml鍙妋yid.properties锛?/h3>

澶囦唤鍘熸湁鏈嶅姟鍣ㄩ厤缃枃浠秙erver.xml鍚庯紝灏嗘暣涓猻erver.xml鏀瑰啓鎴愬涓嬪唴瀹癸細


<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mycat:server SYSTEM "server.dtd">
<mycat:server xmlns:mycat="http://io.mycat/">

  <system>
    <property name="useSqlStat">0</property>
    <property name="useGlobleTableCheck">0</property>
    <property name="sequnceHandlerType">2</property>
    <property name="processorBufferPoolType">0</property>
    <property name="handleDistributedTransactions">0</property>
    <property name="useOffHeapForMerge">1</property>
    <property name="memoryPageSize">1m</property>
    <property name="spillsFileBufferSize">1k</property>
    <property name="useStreamOutput">0</property>
    <property name="systemReserveMemorySize">384m</property>
    <property name="useZKSwitch">false</property>
    <property name="serverPort">8066</property>
    <property name="managerPort">9066</property>
  </system>

  <user name="mycat_root">
    <property name="password">123456</property>
    <property name="schemas">TESTDB</property>
  </user>

  <user name="user">
    <property name="password">user</property>
    <property name="schemas">TESTDB</property>
    <property name="readOnly">true</property>
  </user>

</mycat:server>

澶囦唤鍘熸湁ZooKeeper杩炴帴鏂囦欢myid.properties鍚庯紝灏嗘暣涓猰yid.properties鏀瑰啓鎴愬涓嬪唴瀹癸細


loadZk=false
zkURL=192.168.35.121:2181,192.168.35.123:2181
clusterId=mycat-cluster-1
myid=mycat_fz_01
clusterNodes=mycat_fz_01,mycat_fz_02
type=server
boosterDataHosts=dn00,dn01,dn02

閮ㄧ讲缁撴灉

鍚姩MyCat

纭MySQL鏁版嵁鑺傜偣锛?92.168.35.125锛夋甯歌繍浣滃悗锛屽湪MyCat鑺傜偣锛?92.168.35.121锛変笂锛屼互鎿嶄綔绯荤粺鐢ㄦ埛root鎵ц浠ヤ笅鍛戒护锛屽惎鍔∕yCat銆?/p>


sudo -u mysql /usr/local/mycat/bin/mycat start

MyCat铏氭嫙搴撹闂祴璇?/h3>

鍦∕ySQL鏁版嵁鑺傜偣锛?92.168.35.125锛変笂锛屼娇鐢ㄥ涓嬭鍙ユ墦寮€鍒癕yCat鐨勮繛鎺?/em>銆?/p>


mysql -h192.168.35.121 -P8066 -umycat_root -p123456

  • 鏌ヨ

    浣跨敤鍒癕yCat鐨勮繛鎺?/em>锛屾墽琛屼互涓婼QL锛屾煡璇㈣櫄鎷熻〃TESTDB.test_tbl鐨勬墍鏈夊唴瀹广€?/p>


USE TESTDB
SELECT * FROM test_tbl;

灞忓箷鏄剧ず濡備笅锛屾爣蹇楃潃鎴戜滑宸茬粡鍙互閫氳繃璁块棶铏氭嫙琛═ESTDB.test_tbl锛屾潵鑾峰彇鍒嗗竷鍦ㄤ笉鍚岀墿鐞嗗簱mycat00銆乵ycat01鍜宮ycat02閲岀殑鍚屽悕鐗╃悊琛╰est_tbl鐨勬墍鏈夋暟鎹€?/p>


+----+---------------------+
| id | date                |
+----+---------------------+
|  0 | 2000-01-01 00:00:00 |
|  2 | 2000-03-01 00:00:00 |
|  1 | 2000-02-01 00:00:00 |
+----+---------------------+
3 rows in set (0.01 sec)

  • 澧炲垹鏀?/p>

    浣跨敤鍒癕yCat鐨勮繛鎺?/em>锛屾墽琛屼互涓婼QL锛岃繘琛屼互涓嬫搷浣滐細

  1. 鎻掑叆1999骞淬€?000骞?鏈堝悗鐨勫悎璁?鏉¤褰曪紱

  2. 鍒犻櫎鍘熷鏁版嵁锛?000骞?鏈堬綖3鏈堢殑3鏉¤褰曪級锛?/p>

  3. 淇敼鏂版彃鍏ョ殑2000骞?鏈堝悗鐨勪笁鏉¤褰曪紝璁╁畠浠殑id鍒楀彉鎴?浣嶆暟锛?/p>

  4. 鏌ヨ铏氭嫙琛═ESTDB.test_tbl杩欐椂鍊欐湁鐨勬墍鏈夎褰曘€?/p>


USE TESTDB

INSERT INTO test_tbl(id,date)
VALUES (3,鈥?999-10-01鈥?span class="token punctuation">);
INSERT INTO test_tbl(id,date)
VALUES (4,鈥?999-11-01鈥?span class="token punctuation">);
INSERT INTO test_tbl(id,date)
VALUES (5,鈥?999-12-01鈥?span class="token punctuation">);

INSERT INTO test_tbl(id,date)
VALUES (6,鈥?000-04-01鈥?span class="token punctuation">);
INSERT INTO test_tbl(id,date)
VALUES (7,鈥?000-05-01鈥?span class="token punctuation">);
INSERT INTO test_tbl(id,date)
VALUES (8,鈥?000-06-01鈥?span class="token punctuation">);

DELETE FROM test_tbl
WHERE date BETWEEN
鈥?000-01-01鈥?AND 鈥?000-03-01鈥?span class="token punctuation">;

UPDATE test_tbl
SET id=id+100
WHERE date > 鈥?000-01-01鈥?span class="token punctuation">;

SELECT * FROM test_tbl;

灞忓箷鏈€鍚庝細鏄剧ず濡備笅鍐呭銆傛垜浠凡缁忓彲浠ラ€氳繃铏氭嫙琛═ESTDB.test_tbl杩涜澧炲垹鏀规搷浣滀簡銆?/p>


+-----+---------------------+
| id  | date                |
+-----+---------------------+
|   3 | 1999-10-05 00:00:00 |
| 106 | 2000-04-01 00:00:00 |
|   4 | 1999-11-05 00:00:00 |
| 107 | 2000-05-01 00:00:00 |
|   5 | 1999-12-05 00:00:00 |
| 108 | 2000-06-01 00:00:00 |
+-----+---------------------+
6 rows in set (0.02 sec)

MySQL鐗╃悊搴撴鏌?/h3>

鍦∕ySQL鏁版嵁鑺傜偣锛?92.168.35.125锛変笂锛屼娇鐢ㄥ涓嬭鍙ユ墦寮€鍒癕ySQL鐗╃悊搴撶殑杩炴帴锛屾煡鐪嬪悇涓墿鐞嗗簱鐨勫唴瀹广€?/p>


mysql -h192.168.35.125 -P3306 -uroot -proot -e"
SELECT 鈥榤ycat00鈥?id,date 
FROM mycat00.test_tbl;

SELECT 鈥榤ycat01鈥?id,date 
FROM mycat01.test_tbl;

SELECT 鈥榤ycat02鈥?id,date 
FROM mycat02.test_tbl;
"

灞忓箷鏈€鍚庝細鏄剧ず濡備笅鍐呭銆傛垜浠缃殑鍒嗙墖璺敱瑙勫垯璧蜂簡鏁堟灉锛屽鍒犳敼鐨勬搷浣滃弽鏄犲埌浜嗗搴旂殑鐗╃悊搴撲腑銆?/p>


+---------+-----+---------------------+
| mycat00 | id  | date                |
+---------+-----+---------------------+
| mycat00 |   3 | 1999-10-05 00:00:00 |
| mycat00 | 106 | 2000-04-01 00:00:00 |
+---------+-----+---------------------+
+---------+-----+---------------------+
| mycat01 | id  | date                |
+---------+-----+---------------------+
| mycat01 |   4 | 1999-11-05 00:00:00 |
| mycat01 | 107 | 2000-05-01 00:00:00 |
+---------+-----+---------------------+
+---------+-----+---------------------+
| mycat02 | id  | date                |
+---------+-----+---------------------+
| mycat02 |   5 | 1999-12-05 00:00:00 |
| mycat02 | 108 | 2000-06-01 00:00:00 |
+---------+-----+---------------------+

 

以上是关于SuSE涓婅繍琛孧yCat锛堜簩锛夛細閰嶇疆鍗曠偣MyCat的主要内容,如果未能解决你的问题,请参考以下文章

Spring Cloud Alibaba锛堜簩锛?閰嶇疆涓績澶氶」鐩€佸閰嶇疆鏂囦欢銆佸垎鐩綍瀹炵幇

python dlib瀛︿範锛堜簲锛夛細姣斿浜鸿劯

銆怬racle Database銆慜racle RAC锛堜節锛夛細绠$悊宸ュ叿--crsctl & srvctl

TCP鍗忚鎺㈢┒锛堜笁锛夛細RTT銆佹粦鍔ㄧ獥鍙e拰闃诲澶勭悊

ASP.NET Core绠¢亾娣卞害鍓栨瀽锛?锛夛細绠¢亾鏄浣曞鐞咹TTP璇锋眰鐨勶紵

gulp4.0鐨勪娇鐢ㄥ拰gulpfile.js浠诲姟閰嶇疆

(c)2006-2024 SYSTEM All Rights Reserved IT常识