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:
- Interception β the client request reaches the proxy.
- Analysis/Modification β the proxy parses SQL (for example, determines the operation type:
SELECT,INSERT,UPDATE,DELETE) and can modify the query (addWHERE,LIMIT, logging, etc.).The original MySQL Proxy used Lua scripts for this logic.
- 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.
- 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
| Category | Responsibilities | Use cases |
|---|---|---|
| Scalability | Read/Write Split, load balancing, sharding | Distributing load in a cluster |
| Availability | Failover, server health monitoring | Automatic switch-over on failure |
| Optimization | Caching, multiplexing, pooling | Reducing DB load |
| Security | Auditing, filtering, blocking SQL injections | Logging, whitelist/blacklist |
| Observability | Query statistics, profiling | Finding slow queries |
Types of MySQL Proxy
1. SQL-Aware Proxies (understand SQL and the MySQL protocol)
| Proxy | Vendor | Main features | Multiplexing | Result caching | Read/Write Split | Failover | Sharding | Active maintenance |
|---|---|---|---|---|---|---|---|---|
| ProxySQL | ProxySQL Team | High performance, Query Rules, monitoring, caching | β Yes | β Yes | β Yes | β Yes | β No | β Yes (active) |
| MaxScale | MariaDB | Plugin architecture, monitors, filters, audit | β No | β No | β Yes | β Yes | β Yes (via plugins) | β Yes |
| MySQL Router | Oracle | Simplicity, integration with InnoDB Cluster | β No | β No | β Yes | β Yes | β No | β Yes |
| Vitess (VTGate) | YouTube / CNCF | Scaling 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)
| Proxy | Description | Limitations |
|---|---|---|
| HAProxy | High-performance TCP/HTTP load balancer | Does not parse SQL β read/write split only by ports/IP |
| Keepalived | Provides a VIP (virtual IP) for HA | Not 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?
| Task | Recommendation | Why |
|---|---|---|
| Read/Write Split + cache + multiplexing | ProxySQL | Lightweight, fast, flexible rules |
| MariaDB + plugins + sharding | MaxScale | Deep integration with MariaDB |
| MySQL InnoDB Cluster / Group Replication | MySQL Router | Official support from Oracle |
| Scaling to 1000+ shards (cloud) | Vitess | Large-scale architecture |
| Simple balancer in front of multiple ProxySQL | HAProxy + Keepalived | TCP-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.