mysql driven architecture - to try to solve the problem of separate read and write

About ReplicationDriver a separate program to read and write

How to use two

    1 configuration access string 

      Similar  address = (host = 192.168.5.128) ( port = 3306) (type = master / slave)

    完整串 jdbc:mysql:replication://[master host][:port],[slave host 1][:port][,[slave host 2][:port]]...[/[database]][?propertyName1=propertyValue1[&propertyName2=propertyValue2]...]

    ReplicationDriver default the first database server as Master database, the database server as a follow-up from the other database.

  Principle 2 judgment

     Mysql driver uses the value of what use master or slave database, depending on Connection.getReadOnly () of.

         1 If the value is false, then the command is sent to the master database

         2 If the value is true, the command is sent to the slave database.

         3 When multiple slave database, using the round robin scheduling (round-robin) algorithm to select a slave station database.

  3 settings according to the principles of the program

         写  conn.setReadOnly(false);

           读  conn.setReadOnly(true);

           jdbc master string set for the VIP 

  4 Related Thinking

        1 When the cluster appears two read_only = NO, what happens 

        2 When a library from the shelf, whether the program will poll errors

       3 When copying errors from the library is, if they would call

  4 paper records only for Bowen sources https://www.iteye.com/blog/leitelyaya-2335195 follow-up research will be to test add mongo it is to have the type of drive to achieve a separate read and write

       

 

Guess you like

Origin www.cnblogs.com/danhuangpai/p/11482408.html