Русский flag Русский

MySQL Proxy: A Database Intermediary πŸ› οΈ

Published on 2025-10-28

MySQL Proxy is a proxy application that sits between client applications (for example, your web server) and one or more MySQL servers. It uses the MySQL Network Protocol, which allows any standard MySQL-compatible client to connect to the proxy without changes, believing it is talking directly to a MySQL server.


How MySQL Proxy Works

In its basic configuration the proxy simply forwards requests from the client to the MySQL server and returns responses back.
However the key feature of MySQL Proxy and its counterparts is monitoring, analyzing, and modifying the passing traffic:

  1. Interception β€” the client request reaches the proxy.
  2. Analysis/Modification β€” the proxy parses SQL (for example, determines the operation type: SELECT, INSERT, UPDATE, DELETE) and can modify the query (add WHERE, LIMIT, logging, etc.).

    The original MySQL Proxy used Lua scripts for this logic.

  3. Routing/Action β€” based on the analysis:
    • Send to the master (writes) or replica (reads).
    • Balance load (Round-Robin, least connections, etc.).
    • Multiplex connections β€” thousands of clients β†’ tens of backend connections.
  4. Response handling β€” modify or analyze the result before returning to the client.

All this β€” without changing application code or the MySQL server.


Main Features and Responsibilities

CategoryResponsibilitiesUse cases
ScalabilityRead/Write Split, load balancing, shardingDistributing load in a cluster
AvailabilityFailover, server health monitoringAutomatic switch-over on failure
OptimizationCaching, multiplexing, poolingReducing DB load
SecurityAuditing, filtering, blocking SQL injectionsLogging, whitelist/blacklist
ObservabilityQuery statistics, profilingFinding slow queries

Types of MySQL Proxy

1. SQL-Aware Proxies (understand SQL and the MySQL protocol)

ProxyVendorMain featuresMultiplexingResult cachingRead/Write SplitFailoverShardingActive maintenance
ProxySQLProxySQL TeamHigh performance, Query Rules, monitoring, cachingβœ… Yesβœ… Yesβœ… Yesβœ… Yes❌ Noβœ… Yes (active)
MaxScaleMariaDBPlugin architecture, monitors, filters, audit❌ No❌ Noβœ… Yesβœ… Yesβœ… Yes (via plugins)βœ… Yes
MySQL RouterOracleSimplicity, integration with InnoDB Cluster❌ No❌ Noβœ… Yesβœ… Yes❌ Noβœ… Yes
Vitess (VTGate)YouTube / CNCFScaling to thousands of shards, cloud-nativeβœ… Yesβœ… Yes (limited)βœ… Yesβœ… Yesβœ… Yesβœ… Yes

Note:

  • Multiplexing β€” only ProxySQL and Vitess.
  • SELECT result caching β€” only ProxySQL and Vitess.
  • Sharding β€” Vitess and MaxScale (with plugins).

2. TCP/Layer 4 Proxies (work at the connection level)

ProxyDescriptionLimitations
HAProxyHigh-performance TCP/HTTP load balancerDoes not parse SQL β†’ read/write split only by ports/IP
KeepalivedProvides a VIP (virtual IP) for HANot a proxy, but a tool for high availability of the proxy itself

Recommendation: HAProxy is often used in combination with an SQL-aware proxy (for example, HAProxy β†’ multiple ProxySQL instances).


⚠️ Important: The Original MySQL Proxy (from Oracle)

Deprecated and unsupported since 2014 (last release β€” 0.8.5).
Not recommended for production use.
All of its features (and much more) are implemented in modern alternatives.

ℹ️ Oracle does not develop the open-source MySQL Proxy.
In MySQL Enterprise there is MySQL Router, but it does not replace a full SQL-aware proxy.


Example: Simple ProxySQL Configuration (Read/Write Split)

-- Define backends
insert into mysql_servers(hostgroup_id, hostname, port) values 
  (10, 'mysql-master', 3306),  -- hostgroup 10 = writes
  (20, 'mysql-slave-1', 3306), -- hostgroup 20 = reads
  (20, 'mysql-slave-2', 3306);

-- Rule: SELECT β†’ to replicas, everything else β†’ to master
insert into mysql_query_rules(rule_id, active, match_pattern, destination_hostgroup) values
  (1, 1, '^SELECT.*FOR UPDATE$', 10),
  (2, 1, '^SELECT', 20),
  (3, 1, '.*', 10);

load mysql servers to runtime;
save mysql servers to disk;
load mysql query rules to runtime;
save mysql query rules to disk;

How to Choose a Proxy?

TaskRecommendationWhy
Read/Write Split + cache + multiplexingProxySQLLightweight, fast, flexible rules
MariaDB + plugins + shardingMaxScaleDeep integration with MariaDB
MySQL InnoDB Cluster / Group ReplicationMySQL RouterOfficial support from Oracle
Scaling to 1000+ shards (cloud)VitessLarge-scale architecture
Simple balancer in front of multiple ProxySQLHAProxy + KeepalivedTCP-level + HA

Conclusion

MySQL Proxy is a powerful tool for scalability, fault tolerance, and security of databases. Modern solutions (ProxySQL, MaxScale, Vitess) have completely replaced the outdated original proxy from Oracle.

Choose an SQL-aware proxy if you need flexibility. Use a TCP-proxy only for simple scenarios or in combination.

Need help?

Get in touch with me and I'll help solve the problem

Related Posts