Search code examples
phpmysqlmysqliround-robin

mysqli connection not working with round robin dns


I am trying to setup a round robin MySQL Server (Master-Master) with the same DNS. Everything is working fine, even if I stopped any mysql-server. The problem is when one of the mysql-server is turned off, the php mysqli connection is not working anymore and after 30 sec is automatically killed.

Any idea why is this happening? What can I do?


Solution

  • Round-robin DNS is only possible if every one of your endpoints works. Disabling one of the servers will cause services to randomly fail. There's no guarantee that retrying will give you a different server, some operating systems strongly favour the first entry in whatever random order the IPs are returned in.

    What you need is a load-balancing TCP proxy that can add or remove servers from the pool. Something like HAProxy is a good place to start, but you may find theres's something more MySQL specific that fits your needs better.

    Round-robin DNS is the worst possible way to do database clustering. Avoid it at all costs.