通過mycat實現mysql的讀寫分離

來源:互聯網
上載者:User

標籤:datanode   inf   word   讀寫   使用者名稱   xmlns   gre   最大   下載   

mysql的主從配置沿用上一篇部落格的配置:https://www.cnblogs.com/MasterSword/p/9434169.html

mycat:http://www.mycat.io/

實驗版本:Mycat-server-1.6-release 

# cd /usr/local# mv ~/Mycat-server-1.6-RELEASE-20161028204710-linux.tar.gz /usr/local# tar -zxvf Mycat-server-1.6-RELEASE-20161028204710-linux.tar.gz
# cd /usr/local/mycat/conf/
# vim server.xml 查看mycat使用者的預設配置

<!-- mycat的預設使用者配置,保持不變即可 -->
<user name="root">
  <property name="password">123456</property>
  <property name="schemas">TESTDB</property>
</user>

  # vim schema.xml 修改schema配置讀寫分離

<?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="student" dataNode="dn1" />
  </schema>
  <!-- 設定物理庫 -->
  <dataNode name="dn1" dataHost="localhost1" database="test" />  
    <!-- balance=1設定為讀寫分離 -->
    <dataHost name="localhost1" maxCon="1000" minCon="10" balance="1" writeType="0" dbType="mysql" dbDriver="native" switchType="1" slaveThreshold="100">
    <heartbeat>select user()</heartbeat>
    <!-- 讀庫配置 -->
    <writeHost host="hostM1" url="xxx.xxx.xxx.xxx:3306" user="root" password="xxxxxx">
      <!-- 讀庫配置,可配置多個讀庫 -->
      <readHost host="hostS2" url="xxx.xxx.xxx.xxx:3316" user="root" password="xxxxxx" />
    </writeHost>
  </dataHost>
</mycat:schema>

# cd ../bin
# ./mycat start 啟動mycat
# ps -aux | grep mycat 查看mycat是否啟動成功

在用戶端建立一個連結到mycat的資料庫連接,使用者名稱密碼為server.xml中配置的使用者

  

串連中庫為TESTDB,也是在server.xm中配置的

下面驗證讀寫分離

mycat:

寫庫:

讀庫:

修改讀庫的資料:

mycat中的資料和讀庫資料一致:

停止讀庫的服務:

mycat插入一條資料:

寫庫中存在插入的資料:

 

至此通過mycat實現mysql的讀寫分離配置成功。

ps.mycat最大的功能在於對資料庫分區的處理,如果有機會,以後會進行相關的實驗。

 

通過mycat實現mysql的讀寫分離

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.