简体   繁体   English

ReplicationDriver的工作方式

[英]How ReplicationDriver works

I am curious how com.mysql.jdbc.ReplicationDriver works. 我很好奇com.mysql.jdbc.ReplicationDriver的工作方式。 I have configuration with 1master & 1slave. 我已使用1master和1slave配置。

I want to force some queries to JUST on slave. 我想强制对奴隶进行一些查询。 But it selects DB randomly and sometimes run it on master. 但是它随机选择数据库,有时在主数据库上运行它。

Is it a way to force readonly connection to use just slave DB and never master? 是否有一种方法可以强制只读连接仅使用从数据库而不使用主数据库?

For the ReplicationDriver to know that queries can go to read-only slaves, two conditions need to be met: 为了使ReplicationDriver知道查询可以转到只读从属,需要满足两个条件:

Auto commit needs to be turned off. (*)
Connection needs to be set to read-only.

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM