0

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?

Hooman Bahreini
  • 14,480
  • 11
  • 70
  • 137

2 Answers2

2

Edit: This bug is fixed in MySQL Connector/NET 8.0.19, so you can use your connection string as-is by updating the NuGet package.


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.

Bradley Grainger
  • 27,458
  • 4
  • 91
  • 108
  • Thanks a lot, yes I saw your other post yesterday, and that's how I learnt about the bug... so looks like, the only solution for my case is to use a load balancer (like HAProxy)... but does it mean that I need to add an extra server for load balancer? I wanted to avoid this, because of the cost of running an additional server on AWS for load balancer... – Hooman Bahreini May 24 '19 at 00:30
  • I have seen [Oracle's documentation about load balancing with connector/NET](https://blogs.oracle.com/mysql/how-to:-using-replication-load-balancing-with-connectornet) but it seems to be for Master/Slave scenario. Do you know if I can use this solution with multiple masters? i.e. having `IsMaster="true"` for all 3 servers? – Hooman Bahreini May 24 '19 at 00:32
  • 1
    You might be able to use AWS Elastic Load Balancing to balance TCP traffic (on port 3306) between multiple MySQL servers. I've never tried it, but if it is similar to HAProxy, it should work. – Bradley Grainger May 24 '19 at 00:32
  • 1
    I'm not familiar with the `` configuration for MySQL. If that still works in the latest MySql.Data then it seems worthwhile looking into first. – Bradley Grainger May 24 '19 at 00:35
0

This bug has been fixed in Connector/NET version 8.0.19

See the release notes here: https://insidemysql.com/

Hooman Bahreini
  • 14,480
  • 11
  • 70
  • 137