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
- 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://
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