Rules in mysql_query_rules

15 views
Skip to first unread message

Vladimir Lupu

unread,
Nov 28, 2025, 8:03:52 AM (10 days ago) Nov 28
to proxysql
Hi Team,
I have configured ProxySQL like this:
ProxySQL Admin 1 > select * from mysql_servers;
+--------------+---------------+------+-----------+--------+----------+-------------+-----------------+---------------------+---------+----------------+---------------+
| hostgroup_id | hostname      | port | gtid_port | status | weight   | compression | max_connections | max_replication_lag | use_ssl | max_latency_ms | comment       |
+--------------+---------------+------+-----------+--------+----------+-------------+-----------------+---------------------+---------+----------------+---------------+
| 1            | 192.168.0.135 | 3306 | 0         | ONLINE | 1        | 0           | 600             | 0                   | 0       | 0              | DEB_TEST_DB_1 |
| 2            | 192.168.1.84  | 3306 | 0         | ONLINE | 10000000 | 0           | 600             | 5                   | 0       | 100            | DEB_TEST_DB_2 |
| 2            | 192.168.1.205 | 3306 | 0         | ONLINE | 10000000 | 0           | 600             | 5                   | 0       | 100            | DEB_TEST_DB_3 |
| 2            | 192.168.0.135 | 3306 | 0         | ONLINE | 1        | 0           | 600             | 0                   | 0       | 0              | DEB_TEST_DB_1 |
+--------------+---------------+------+-----------+--------+----------+-------------+-----------------+---------------------+---------+----------------+---------------+

ProxySQL Admin 1 > select * from mysql_users where default_hostgroup=1;
+------------------+-----------+--------+---------+-------------------+----------------+---------------+------------------------+--------------+---------+----------+-----------------+------------+---------+
| username         | password  | active | use_ssl | default_hostgroup | default_schema | schema_locked | transaction_persistent | fast_forward | backend | frontend | max_connections | attributes | comment |
+------------------+-----------+--------+---------+-------------------+----------------+---------------+------------------------+--------------+---------+----------+-----------------+------------+---------+
| app_proxysql_web | ********* | 1      | 0       | 1                 | NULL           | 0             | 1                      | 0            | 1       | 1        | 10000           |            |         |
+------------------+-----------+--------+---------+-------------------+----------------+---------------+------------------------+--------------+---------+----------+-----------------+------------+---------+

ProxySQL Admin 1 > select * FROM mysql_query_rules_fast_routing;
+------------------+------------+--------+-----------------------+-------------------------------+
| username         | schemaname | flagIN | destination_hostgroup | comment                       |
+------------------+------------+--------+-----------------------+-------------------------------+
| app_proxysql_web | tast_db_1  | 0      | 1                     | fast query route to tast_db_1 |
| app_proxysql_web | test_db_2  | 0      | 1                     | fast query route to test_db_2 |
+------------------+------------+--------+-----------------------+-------------------------------+

ProxySQL Admin 1 > select rule_id, active, schemaname, flagIN, flagOUT, proxy_port, match_digest, match_pattern, negate_match_pattern, destination_hostgroup, multiplex, apply FROM mysql_query_rules where destination_hostgroup in (1,2);
+---------+--------+------------+--------+---------+------------+--------------+--------------------+----------------------+-----------------------+-----------+-------+
| rule_id | active | schemaname | flagIN | flagOUT | proxy_port | match_digest | match_pattern      | negate_match_pattern | destination_hostgroup | multiplex | apply |
+---------+--------+------------+--------+---------+------------+--------------+--------------------+----------------------+-----------------------+-----------+-------+
| 1       | 1      | NULL       | 0      | NULL    | 6401       | NULL         | /\* temp_table \*/ | 0                    | 2                     | 0         | 1     |
| 2       | 1      | NULL       | 0      | NULL    | 6401       | ^SELECT      | NULL               | 1                    | 1                     | 0         | 1     |
| 3       | 1      | NULL       | 0      | NULL    | 6401       | ^SELECT      | NULL               | 0                    | 2                     | NULL      | 1     |
+---------+--------+------------+--------+---------+------------+--------------+--------------------+----------------------+-----------------------+-----------+-------+

These rules solve the requirement:
Within one connection to ProxySQL, all SELECT queries before the first execution of INSERT/UPDATE/DELETE queries must be balanced between replicas DEB_TEST_DB_2 and DEB_TEST_DB_3

Can't solve requirements:
Within one connection with ProxySQL, after the first execution of INSERT/UPDATE/DELETE queries, subsequent queries, incl. SELECT queries must be executed on the same server on the same ProxySQL connection to MySQL
When data replication lags, all requests in open connection are required to be executed, and only after the connection is closed, the requests are routed to another server without data replication lags.

Please tell me what solution can be applied to these two requirements for test_db_3?

Regards,
VL


Reply all
Reply to author
Forward
Message has been deleted
0 new messages