Plug-in application MyCat

What is MyCat

MyCAT is a from Ali Cobar evolved to support the database , separate read and write, sub-table sub-library distributed middleware. MyCAT supports Oracle, MSSQL, MYSQL, PG, DB2 relational database , but also support non-relational databases such as MongoDB .

MyCAT principle MyCAT mainly through the interception of SQL , and then after a certain rule fragment analysis , route analysis, analysis, analysis of separate read and write buffers and the like, and then sent to the rear end of the SQL real data block, and return the results do the process returns to the appropriate client. MyCat is written in java.

Separate read and write on MyCat

Separate read and write, is simply to separate read and write operations to the database to correspond to different database servers . Primary database provides the write operation, a read operation provided from the database, this can effectively reduce the pressure of a single database. After the primary database is written, the data synchronized in time to read the database as much as possible to ensure consistent reading and writing of data database, such as MySQL master-slave replication, Oracle's data guard, subscription copy of SQL Server and so on. 

Reading database: only do select.

Write database: select, create, insert, delete, update.

Separate read and write, how to route to different database access?

MyCat principle: will intercept all JDBC client's request, according to the judgment sql statement forwarded to a different database operations.

MyCat similar Nginx:

MyCat database can achieve reverse proxy, ip address hide the real database, load balancing, blacklist, slice and so on.

Linux environment to install MyCat read and write separation

1, upload installation Mycat-server-1.6.5-release-20180122220033-linux.tar

2, extracting installation package tar -zxvf

3, configuration and server.xml schema.xml

4, client connections Port number: 8066 profile introduction:

Profile Introduction:

Linux environment to install MyCat read and write separation

1, go to the bin directory to start MyCat ./mycat start stop MyCat ./mycat stop

2, see the / usr / local / mycat / logs wrapper.log log if it is to successfully launch the successful

Turn off the firewall: systemctl stop firewalld.service

Read only account user user port number 8066

Readable and writable account root 123456 port number 8066

 

SpringBoot project integration dynamic data sources (separate read and write)

1. Configure multiple data sources to access different data according to business needs, specify the corresponding strategies: add, delete, modify operation corresponding data access, query access corresponding data, different databases to do data processing consistency. Because this method is relatively easy to understand, simple, do not do too much introduction.

2. Dynamic switching data sources, according to the configuration files, dynamic switching service database access: this scheme is achieved by the Spring AOP, AspactJ the weaving, implemented in Spring inherits AbstractRoutingDataSource programmed to implement dynamic switching database access, not only can facilitate the expansion, without prejudice to existing procedures, but also for additions and deletions of this feature is relatively easy.

3. achieved by separate read and write mycat: myCat using separate read and write functions provided, connected to a plurality of myCat database, the data need only connect myCat, for developers he connected a database (actually the intermediate mysql myCat piece), and does not need to choose between different libraries according to different service, so no extra code generation. Detailed reference configuration

Dynamic data sources core configuration

2.0.1 introduced in the Spring of AbstractRoutingDataSource, the DataSource class acts as the intermediary routing, can have at run-time to dynamically switch to a true key value according to some DataSource.

1. Project the need to integrate multiple data sources are read and write data sources, different binding key.

2. The use of AOP whether Yewuluojiceng intercept method, a method of determining the need to write or read a prefix operation

3. If the prefix is ​​a method of operation when the write switch directly write data source, whereas source is switched to the read data can also define their own annotations encapsulation

 

mycat official website: http: //www.mycat.io/

Guess you like

Origin www.cnblogs.com/ming-blogs/p/10963164.html