Need to migrate your e-mails to a new server? Free and paid versions of our online tool available.
Hero Image

HAProxy MySQL Load Balancing on Gentoo Linux

HAProxy MySQL Load Balancing on Gentoo Linux

Config section

listen mysql-cluster
    bind *:3306
    mode    tcp
    option  mysql-check user haproxy_check
    balance leastconn
    server db1 192.168.1.10:3306 check weight 1
    server db2 192.168.1.11:3306 check weight 1
    server db3 192.168.1.12:3306 check weight 1

Create HAProxy check user on each DB node

CREATE USER 'haproxy_check'@'%';
FLUSH PRIVILEGES;

Validate and reload

haproxy -c -f /etc/haproxy/haproxy.cfg
systemctl reload haproxy

Test

mysql -h 127.0.0.1 -P 3306 -u appuser -p -e "SELECT @@hostname;"
# Repeat to see requests distributed