ProxySQL – Query Rules

You may balance the load in a cluster by routing various sorts of traffic to various groups using ProxySQL’s robust feature query rules.

These rules will redirect, rewrite, or refuse requests that match a given regex. In addition to using regex to build the rules, you may also add ports, client addresses, query digests, and usernames to redirect traffic to read replicas.

Routing queries to the different hostgroup by adding query-digest in the query rules:
INSERT INTO mysql_query_rules ( active, apply, digest, destination_hostgroup ) VALUES
( 1, 1, ‘0x11197AA9E2B1B111’, 2 );

Routing queries to the different hostgroup by adding client address in the query rules:
INSERT INTO mysql_query_rules ( active, client_addr, apply,destination_hostgroup) VALUES
( 1, ‘10.0.111.11’, 1,2 );

Routing queries to the different hostgroup by adding username in the query rules:
INSERT INTO mysql_query_rules( active, apply, username, destination_hostgroup) VALUES
(1,1,‘someuser’,2);

Adding regex in the query rules:
INSERT INTO mysql_query_rules (active, match_digest, apply,destination_hostgroup) VALUES
(1, ‘^SELECT Col1.*’, 1,2);

Adding incoming port into query rules:
INSERT INTO mysql_query_rules (rule_id, active, proxy_port, destination_hostgroup, apply)
VALUES (1,1, 3001, 1, 1);

Hope you find this article helpful.

Leave a Reply