问题
Backgroud
I am developing a .net project, which works with EF6 and MySQL DB. For High Availability, I am using Galera cluster, so I have 3 MySQL Master nodes up and running: master1, master2 and master3.
According to connectionstring.com I should be able to use the following connection string:
Server=master1, master2, master3;Database=myDataBase;
Uid=myUsername;Pwd=myPassword;
I have tried the above, and it does not work... I have seen this bug which explains multi-host connection string does not work.
Question
According to this link I can use mysql:loadbalance:
in front of my JDBC connection string. The problem is I don't know which MySQL Connector am I using? I believe I have installed the Standard/Default Nuget Packages for .net (MySQL.Data and MySQL.Data.EntityFramework). Any idea which MySQL Connector come with the above packages?
Any idea how can I use MySQL connector to load balance/connect the 3 Master nodes?
回答1:
This isn't supported by MySQL.Data. As you observed, there are multiple bug reports (#81650, #88962) pointing out this problem, but it hasn't been fixed in three years.
As explained here, there is an alternative MySQL library, MySqlConnector, that does support this connection string syntax. Unfortunately, there is no EF6 library available for it. (There is an EF.Core package, Pomelo.EntityFrameworkCore.MySql.)
A workaround would be to create a layer 4 load balancer in front of your three Galera nodes. Galera provides documentation on how to do this with HAProxy. Your C# MySQL client would connect to HAProxy, and it would load balance connections between your Galera servers.
回答2:
This bug has been fixed in Connector/NET version 8.0.19
See the release notes here: https://insidemysql.com/
来源:https://stackoverflow.com/questions/56274136/connectionstring-for-connecting-3-master-nodes-to-mysql