Search code examples
gogo-gormgalera

gorm and galera connect


I am using GORM for my golang project with a mariadb bdd, but we are migrating to a galera cluster which seems to be exactly the same with multiples node... I cannot find any information on the connexion string to use ... for now it looks like :

db, err = gorm.Open("mysql", conf.BDDUSER+":"+conf.BDDPASS+"@tcp("+conf.BDDHOST+":"+BDDPort+")/"+conf.BDDSCHEMA+"?charset=utf8&parseTime=True")

but now we need to include all the 3 nodes in there.


Solution

  • As recommended by the developer of gorm, you should use a load balancer to connect to multiple databases. After you have a load balancer, you can use that as the connection string.

    Source: https://github.com/jinzhu/gorm/issues/1055 , https://github.com/jinzhu/gorm/issues/1024