MyCat sub-library sub-table - Exercise

Simulate such a scenario:

    1, by business database "vertical" split into user database and order database;

    2, separate read and write user library shots from;

    3, order store do "horizontal" slicing, each slice of the table and the shots from separate read and write,;

 

A vertical segmentation

  1. Prepare two MySQL database

       

 

  2, MyCat profile

    schema.xml

     

    server.xml (mostly modify schemas, schema modifications to the name schemas.xml)

     

 

    Start mycat, two tables appeared.

     

 

    Insert a data view mycat and user libraries have the data, and then further in order to insert a table.

         

 

    Practical associated with these two libraries in two tables look, I insert two tables of data id is 1, so by id associated error, and now can not cross the library association, be resolved through the application layer interface calls it In fact there is a solution, and then behind the in-depth study to resolve.

     

 

    Good, vertical slicing is completed.

Second, separate read and write from the master user database,

  1, to prepare a MySQL, as the user base slave, master-slave database to the same table two.

  2, modify mycat profile, schema.xml, is to add a configuration

    

 

    Balance:
                        1. Balance = "0", do not open the separate read and write, a read operation is sent to all the currently available writeHost.
                        2. balance = "1", all read operations are random sent to all nodes other than the first writeHost.
                        3. balance = "2", all read operations are random in writeHost, the distribution readhost.

        4. balance = "3", all reads are randomly distributed over readhost.

    We modify the data users table node from it, it is easy to see which library to read the data.

          

 

    发现,不管查多少次,都是主节点的,我们把banlance改成2,发现查询的数据再主从节点上来回切换。把balance改成3,只查询从节点了。

 

    还缺少一个主从节点的数据同步,这块就略过了,在《主从》那篇你有。

 

三、订单库,水平切分

  

 

 

 

  

     

 

 

 

 

 

 

     

 

Guess you like

Origin www.cnblogs.com/hmxs/p/12329439.html