MySQL分布式jdbc连接

参考文档:

https://dev.mysql.com/doc/connector-j/5.1/en/connector-j-multi-host-connections.html

服务器故障转移

连接格式:

jdbc:mysql://[primary host][:port],[secondary host 1][:port][,[secondary host 2][:port]]...[/[database]]...

 驱动程序每次获取连接时,都是优先尝试连接第一台主机,如果通讯异常连接失败,则会按顺序连接第二台、第三台

 负载均衡

连接格式:

jdbc:mysql:loadbalance://[host1][:port],[host2][:port][,[host3][:port]]...[/[database]] »
[?propertyName1=propertyValue1[&propertyName2=propertyValue2]...]

 这种方式,服务器列表里,每一台服务器都可以读写

主从复制

jdbc:mysql:replication://[master host][:port],[slave host 1][:port][,[slave host 2][:port]]...[/[database]] »
[?propertyName1=propertyValue1[&propertyName2=propertyValue2]...]

多个主(Master)

jdbc:mysql://address=(type=master)(host=master1host),address=(type=master)(host=master2host),address=(type=slave)(host=slave1host)/database
原文地址:https://www.cnblogs.com/qiumingcheng/p/10262570.html