Multi-Host Connections(三)

原创
2018/06/06 17:17
阅读数 395

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

展开阅读全文
加载中
点击引领话题📣 发布并加入讨论🔥
打赏
0 评论
1 收藏
0
分享
返回顶部
顶部