MySQL C#连接字符串故障转移 [英] MySQL c# Connection String failover

查看:170
本文介绍了MySQL C#连接字符串故障转移的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道我可以用逗号分隔连接字符串中的主机,它将使用不同的服务器: https://www.connectionstrings.com/mysql-connector-net-mysqlconnection/multiple-servers/

I am aware that I can seperate hosts in the connection string with a comma and it will use different servers: https://www.connectionstrings.com/mysql-connector-net-mysqlconnection/multiple-servers/

例如:Server = serverAddress1,serverAddress2,serverAddress3; Database = myDataBase; Uid = myUsername; Pwd = myPassword;

for example: Server=serverAddress1, serverAddress2, serverAddress3;Database=myDataBase; Uid=myUsername;Pwd=myPassword;

但是我需要一些有关如何特别选择服务器的信息.例如,是循环赛吗?还是顺其自然,直到找到一个可行的?

But I need some information on how it specifically chooses servers. For example, is it round robin? Or does it go in order, until it finds a working one?

如果第一个失败,然后移动到第二个,那么尝试使用第二个要花多长时间?

If the first one fails, and it moves to the second one, how long would it be before it attempted to use the second one?

我愿意接受有关故障转移连接字符串的其他建议

I am open to other suggestions for failover connection strings

TIA -乔

推荐答案

MySQL文档是您的朋友.声明

The MySQL documentation is your friend here. It states

连接URL中的主机列表由两种类型的主机组成 主要次要.启动新连接时, 驱动程序总是首先尝试连接到主主机,如果 必需,按顺序故障转移到列表中的辅助主机 遇到交流问题时.即使最初 与主要主机的连接失败,驱动程序已连接到 次要主机,主要主机永远不会失去其特殊地位

The host list in the connection URL comprises of two types of hosts, the primary and the secondary. When starting a new connection, the driver always tries to connect to the primary host first and, if required, fails over to the secondary hosts on the list sequentially when communication problems are experienced. Even if the initial connection to the primary host fails and the driver gets connected to a secondary host, the primary host never loses its special status

因此,在下面的连接字符串中,第一个主机是主要主机,将首先选择该主机进行连接.仅当此选项不可用时,才会选择辅助主机.它还将尝试尽快回切到主主机,但是可以配置其工作方式.

So in the connection string below, the first host is the primary and will be selected first for connection. Only if this is not available will a secondary host be selected. It will also try to fail back to the primary host ASAP, but how this works can be configured.

jdbc:mysql://[主要主机] [:端口],[辅助主机 1] [:port] [,[备用主机2] [:port]] ... [/[数据库]]» [?propertyName1 = propertyValue1 [& propertyName2 = propertyValue2] ...]

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

https://dev .mysql.com/doc/connector-j/5.1/en/connector-j-config-failover.html

这篇关于MySQL C#连接字符串故障转移的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆