ReplicationDriver
针对Master/Slave,Mysql jdbc drivrer : ReplicationDriver
- Perform read/write work on the master by setting the read-only flag to "false"
conn.setReadOnly(false);
- 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://
另外一种配置方式:
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