简体   繁体   English

使用 MySQL 复制(主/从)与 MyBatis

[英]Using MySQL replication (Master/Slave) with MyBatis

I am just wondering how I can use a Master/Slave MySQL replication database with MyBatis.我只是想知道如何将主/从 MySQL 复制数据库与 MyBatis 一起使用。 JDBC offers a com.mysql.jdbc.ReplicationDriver (see here ), but I couldn't find out where I can use similar things including all the nice properties I can configure ( roundRobinLoadBalance , autoReconnect ,...) in MyBatis. JDBC offers a com.mysql.jdbc.ReplicationDriver (see here ), but I couldn't find out where I can use similar things including all the nice properties I can configure ( roundRobinLoadBalance , autoReconnect ,...) in MyBatis.

Currently I have configured my none-replicated database in MyBatis like this:目前我已经在 MyBatis 中配置了我的非复制数据库,如下所示:

<environments default="development">
    <environment id="development">
        <transactionManager type="JDBC" />
        <dataSource type="POOLED">
            <property name="driver" value="com.mysql.jdbc.Driver" />
            <property name="url"
                value="jdbc:mysql://localhost:3306/database" />
            <property name="username" value="root" />
            <property name="password" value="" />
        </dataSource>
    </environment>
    <environment id="production">
        <transactionManager type="JDBC" />
        <dataSource type="POOLED">
            <property name="driver" value="com.mysql.jdbc.Driver" />
            <property name="url"
                value="jdbc:mysql://xxx:3306/database" />
            <property name="username" value="production" />
            <property name="password" value="" />
        </dataSource>
    </environment>
</environments>

Has anyone aa hint for me?有人给我提示吗?

Thanks for your help.谢谢你的帮助。

Daniel丹尼尔

ANOTHER POSSIBLE ANSWER另一个可能的答案

If you notice, the properties you're setting in the xml for the driver are also common properties set and passed to jdbc.如果您注意到,您在 xml 中为驱动程序设置的属性也是设置并传递给 jdbc 的常用属性。 So, I wouldn't be surprised if MyBatis was just taking them and passing them right into the driver.因此,如果 MyBatis 只是将它们接收并直接传递给驱动程序,我不会感到惊讶。 So maybe try this:所以也许试试这个:

<environments default="development">
    <environment id="development">
        <transactionManager type="JDBC" />
        <dataSource type="POOLED">
            <!-- Just use ReplicationDriver -->
            <property name="driver" value="com.mysql.jdbc.ReplicationDriver" />
            <property name="url"
                value="jdbc:mysql://localhost:3306/database" />
            <property name="autoReconnect" value="true" />
            <property name="roundRobinLoadBalance" value="true" />
            <property name="username" value="root" />
            <property name="password" value="" />
        </dataSource>
    </environment>
    <environment id="production">
        <transactionManager type="JDBC" />
        <dataSource type="POOLED">
            <!-- Just use ReplicationDriver -->
            <property name="driver" value="com.mysql.jdbc.ReplicationDriver" />
            <property name="url"
                value="jdbc:mysql://xxx:3306/database" />
            <property name="autoReconnect" value="true" />
            <property name="roundRobinLoadBalance" value="true" />
            <property name="username" value="production" />
            <property name="password" value="" />
        </dataSource>
    </environment>
</environments>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 将在单主多从复制中的MySQL从属中运行触发器 - will triggers run in MySQL slave in a Single Master Multi-Slave replication mysql主/从复制问题:无法创建PoolableConnectionFactory - mysql master/slave replication issue: Cannot create PoolableConnectionFactory 主从复制jdbc url - Master slave replication jdbc url 配置c3p0连接池的Mysql主从复制中偶尔会遇到到slave的通信链接失败 - Facing Communication link failure to slave occasionally in Mysql master-slave replication configured with c3p0 connection pooling 有没有办法在Quartz Scheduler中拆分读取/写入查询以使用mysql主从复制? - Is there a way to split read/write queries in Quartz Scheduler to use mysql master slave replication? 在主从配置中使用Spring @EnableRedisHttpSession - Using Spring @EnableRedisHttpSession with master-slave configuration 使用com.mysql.jdbc.ReplicationDriver的MySql Master / Slave Spring Hibernate - MySql Master/Slave Spring Hibernate with com.mysql.jdbc.ReplicationDriver mysql故障转移后如何用从数据库的数据更新主数据库 - How to update master database with data of slave database after failover in mysql 使用 MyBatis 将用户信息保存到 MySQL - Saving user info into MySQL using MyBatis 如何使用MyBatis将mysql字段更新为中文 - How to update mysql fields into Chinese using MyBatis
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM