Multi-Host Connections(三)

ReplicationDriver

针对Master/Slave,Mysql jdbc drivrer : ReplicationDriver

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

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

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

conn.setReadOnly(false);

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

conn.setReadOnly(true);

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

  几种MySQL JDBC 驱动的URL前缀:  

URL_PREFIX = "jdbc:mysql://";

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

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

转载于:https://my.oschina.net/masterworker/blog/1825406

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值