SyntaxStudy
Sign Up
MySQL ProxySQL for Load Balancing
MySQL Advanced 5 min read

ProxySQL for Load Balancing

ProxySQL

ProxySQL is a high-performance proxy for MySQL that provides connection pooling, query routing, read/write splitting, and failover without changing application code.

Example
-- ProxySQL admin interface
mysql -u admin -padmin -h 127.0.0.1 -P 6032
-- Add backend servers
INSERT INTO mysql_servers (hostgroup_id, hostname, port)
VALUES (1, "primary", 3306), (2, "replica1", 3306), (2, "replica2", 3306);
-- Route SELECTs to hostgroup 2 (replicas)
INSERT INTO mysql_query_rules (rule_id, active, match_digest, destination_hostgroup)
VALUES (1, 1, "^SELECT", 2);
LOAD MYSQL SERVERS TO RUNTIME; SAVE MYSQL SERVERS TO DISK;
Pro Tip

ProxySQL's query rules use regex matching on query digests — powerful but test rules carefully.