Separation of reading and writing of mysql through mycat

Keywords: MySQL mycat xml Database

The master-slave configuration of mysql follows the configuration of the previous blog: https://www.cnblogs.com/MasterSword/p/9434169.html

MYCAT download address: http://www.mycat.io/

Trial version: 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 view the default configuration of mycat user

<!-- mycat Default user configuration for,Just keep it the same -->
<user name="root">
  <property name="password">123456</property>
  <property name="schemas">TESTDB</property>
</user>

  # vim schema.xml modify schema configuration read write separation

<?xml version="1.0"?>
<!DOCTYPE mycat:schema SYSTEM "schema.dtd">
<mycat:schema xmlns:mycat="http://io.mycat/">
  <schema name="TESTDB" checkSQLschema="false" sqlMaxLimit="100">
    <!-- Set up physical tables -->
    <table name="student" dataNode="dn1" />
  </schema>
  <!-- Set up physical library -->
  <dataNode name="dn1" dataHost="localhost1" database="test" />  
    <!-- balance=1 Set as read-write separation -->
    <dataHost name="localhost1" maxCon="1000" minCon="10" balance="1" writeType="0" dbType="mysql" dbDriver="native" switchType="1" slaveThreshold="100">
    <heartbeat>select user()</heartbeat>
    <!-- Read library configuration -->
    <writeHost host="hostM1" url="xxx.xxx.xxx.xxx:3306" user="root" password="xxxxxx">
      <!-- Read library configuration,Multiple read libraries can be configured -->
      <readHost host="hostS2" url="xxx.xxx.xxx.xxx:3316" user="root" password="xxxxxx" />
    </writeHost>
  </dataHost>
</mycat:schema>

# cd ../bin
# ./mycat start start-up mycat
# ps -aux | grep mycat check if mycat starts successfully

Create a new database connection to mycat on the client side, with the user name and password configured in server.xml

  

The library in the connection is TESTDB, which is also configured in server.xm

Verify read-write separation below

mycat:

Write library:

Library:

Modify the data of the reader:

The data in mycat is consistent with the data in the Reading database:

Stop reading services:

mycat inserts a piece of data:

There is inserted data in the write library:

 

So far, the read-write separation of mysql is successfully configured through mycat.

The biggest function of ps.mycat is to deal with database fragmentation. If there is a chance, related experiments will be carried out in the future.

Posted by bla5e on Sat, 04 Jan 2020 07:06:32 -0800