Multi-Host Connections(三)

ReplicationDriverhtml

針對Master/Slave,Mysql jdbc drivrer : ReplicationDrivermysql

https://dev.mysql.com/doc/connector-j/8.0/en/connector-j-master-slave-replication-connection.htmlsql

http://dev.mysql.com/doc/refman/5.1/en/connector-j-reference-replication-connection.htmloracle

  1. Perform read/write work on the master by setting the read-only flag to "false"

conn.setReadOnly(false);spa

  1. Now, do a query from a slave, the driver automatically picks one from the list

conn.setReadOnly(true);orm

URL配置樣式:jdbc:mysql:replication://master,slave1,slave2,slave3/test?roundRobinLoadBalance=truehtm

  幾種MySQL JDBC 驅動的URL前綴:  get

URL_PREFIX = "jdbc:mysql://";it

REPLICATION_URL_PREFIX = "jdbc:mysql:replication://";io

MXJ_URL_PREFIX = "jdbc:mysql:mxj://";

LOADBALANCE_URL_PREFIX = "jdbc:mysql:loadbalance://";

jdbc:mysql:fabric://

https://docs.oracle.com/cd/E17952_01/mysql-utilities-1.4-en/connector-j-fabric-connect.html

 

另一種配置方式:

jdbc:mysql://address=(type=master)(host=master1host),address=(type=master)(host=master2host),address=(type=slave)(host=slave1host)/database

 

replication drivers舉例

jdbc:mysql:replication//master.amazonaws.com:3306,slave.amazonaws.com:3306/dbsid?failOverReadOnly=true;roundRobinLoadBalance=true&allowMasterDownConnections=true

相關文章
相關標籤/搜索