mysqljs / mysql

A pure node.js JavaScript Client implementing the MySQL protocol.
MIT License
18.28k stars 2.52k forks source link

Any plan for supporting multiple hosts in mysql driver? #2120

Open jimlindeman opened 5 years ago

jimlindeman commented 5 years ago

Some commercial mysql offerings not only offer a haproxy frontend to their mysql server cluster, but also implement >1 haproxy URLs (to HA the haproxy layer). Such is the case with Compose.com's mysql offering (currently beta).

Is there a plan for the configuration options to support a hosts parameter to override the host parameter, which takes in an array of host strings? This is the approach used by other nodejs drivers like elasticsearch: https://www.elastic.co/guide/en/elasticsearch/client/javascript-api/current/auth-reference.html#_https_ssl

dougwilson commented 5 years ago

Hi @jimlindeman I've never heard of this before. You're welcome to make a pull request with the implementation you're looking for. How to contribute is https://github.com/mysqljs/mysql#contributing

dougwilson commented 5 years ago

Also @jimlindeman is this something different from the pool cluster feature? https://github.com/mysqljs/mysql#poolcluster

jimlindeman commented 5 years ago

It looked like pooling was for master/slave designations (i.e. talking with specific hosts behind a haproxy layer)

dougwilson commented 5 years ago

Gotcha. So what exactly is different from that and what you want? Example is just master / slavem you can call them whatever you want and balance across multiple hosts. Seems to me exactly the same as the elasticsearch ezample you gave just different syntax. So is it just you want the syntax to be identical to eslaticsearch one or is there a behavior that is different?

If you don't want to describe exactly what you need created, then you can make a pull request, otherwise I have no idea what you're asking to get implemented at this point.

jimlindeman commented 5 years ago

Okay, if there isn't a designated master/slave hierarchy with that, which the pooling example confused me to think there was, I'll try experimenting with using that pooling like:

var poolCluster = mysql.createPoolCluster(); poolCluster.add('HA-1, haConfig[0]); // add a named configuration poolCluster.add('HA-2', haConfig[1]); poolCluster.add('HA-3', haConfig[2]); var pool = poolCluster.of('*'); pool.query(function (error, results, fields) {});

dougwilson commented 5 years ago

And always happy to take pull requests to improve docs! All the pool cluster docs were written by the original person who contributed the pool cluster implementation.