我正在尝试遵循http://dev.mysql.com/doc/connector-j/en/connector-j-master-slave-replication-connection.html列出的步骤,这些步骤声明
若要启用此功能,请在配置应用服务器的连接池时使用com.mysql.jdbc.ReplicationDriver类
从https://github.com/brettwooldridge/HikariCP -上面写着
HikariCP将尝试完全基于jdbcUrl通过DriverManager解析驱动程序。
那么,这个配置就足够了吗?
db.default.url=jdbc:mysql:replication ...
Squeryl有许多db适配器;但我的理解是这些适配器是不相关的吗?http://squeryl.org/api/index.html#org.squeryl.adapters.MySQLInnoDBAdapter
很抱歉加载关键词-我只是不太确定我需要把注意力集中在什么地方
谢谢布伦特
发布于 2017-09-11 08:16:04
我发现自己回到了这里-请注意,hikari不支持复制驱动程序。
https://github.com/brettwooldridge/HikariCP/issues/625#issuecomment-251613688
MySQL Replication Driver simply does NOT work together with HikariCP.
和
https://groups.google.com/forum/#!msg/hikari-cp/KtKgzR8COrE/higEHoPkAwAJ
... nobody running anything resembling a mission critical application takes MySQL's driver-level replication support seriously.
发布于 2020-09-28 10:35:50
对于2020年的人们来说,Hikari使用
com.mysql.jdbc.jdbc2.optional.MysqlDataSource作为数据源。如果我看一下上面类的代码。它有一个名为Connection的方法,它返回连接实例。
protected Connection getConnection(Properties props) throws SQLException {
String jdbcUrlToUse = null;
if (!this.explicitUrl) {
StringBuffer jdbcUrl = new StringBuffer("jdbc:mysql://");
if (this.hostName != null) {
jdbcUrl.append(this.hostName);
}
jdbcUrl.append(":");
jdbcUrl.append(this.port);
jdbcUrl.append("/");
if (this.databaseName != null) {
jdbcUrl.append(this.databaseName);
}
jdbcUrlToUse = jdbcUrl.toString();
} else {
jdbcUrlToUse = this.url;
}
Properties urlProps = mysqlDriver.parseURL(jdbcUrlToUse, (Properties)null);
urlProps.remove("DBNAME");
urlProps.remove("HOST");
urlProps.remove("PORT");
Iterator keys = urlProps.keySet().iterator();
while(keys.hasNext()) {
String key = (String)keys.next();
props.setProperty(key, urlProps.getProperty(key));
}
return mysqlDriver.connect(jdbcUrlToUse, props);
}的实例mysqlDriver
protected static final NonRegisteringDriver mysqlDriver;如果我检查NonRegisteringDriver类的连接方法。看上去像这样
public Connection connect(String url, Properties info) throws SQLException {
if (url != null) {
if (StringUtils.startsWithIgnoreCase(url, "jdbc:mysql:loadbalance://")) {
return this.connectLoadBalanced(url, info);
}
if (StringUtils.startsWithIgnoreCase(url, "jdbc:mysql:replication://")) {
return this.connectReplicationConnection(url, info);
}
}
Properties props = null;
if ((props = this.parseURL(url, info)) == null) {
return null;
} else if (!"1".equals(props.getProperty("NUM_HOSTS"))) {
return this.connectFailover(url, info);
} else {
try {
com.mysql.jdbc.Connection newConn = ConnectionImpl.getInstance(this.host(props), this.port(props), props, this.database(props), url);
return newConn;
} catch (SQLException var6) {
throw var6;
} catch (Exception var7) {
SQLException sqlEx = SQLError.createSQLException(Messages.getString("NonRegisteringDriver.17") + var7.toString() + Messages.getString("NonRegisteringDriver.18"), "08001", (ExceptionInterceptor)null);
sqlEx.initCause(var7);
throw sqlEx;
}
}
}在查看了代码之后,它看起来支持。我到现在还没试过。试着让你从个人经历中知道。从代码来看,它看起来是直接可行的。
发布于 2015-04-01 13:46:44
Squeryl提供了不同的MySQL适配器,因为innodb支持引用键,而myisam不支持引用键。似乎您的工作应该在连接池级别处理,所以我不认为您的Squeryl配置会有影响。
我从来没有为复制的MySQL配置过Hikari,但是如果它需要一个替代的JDBC驱动程序,那么如果您能够提供JDBC,并且一切都能正常工作,我会感到惊讶。我猜想Hikari的默认功能是选择普通的普通MySQL JDBC驱动程序,除非您告诉它不这样做。幸运的是,Hikari拥有相当多的配置选项,包括设置特定driverClassName的能力。
https://stackoverflow.com/questions/29391693
复制相似问题