{"id":4620,"date":"2026-09-20T04:01:24","date_gmt":"2026-09-19T22:31:24","guid":{"rendered":"https:\/\/cpanelfree.com\/blog\/configuring-proxysql-query-routing-readwrite-splitting-and-connection-caching\/"},"modified":"2026-09-20T04:01:24","modified_gmt":"2026-09-19T22:31:24","slug":"configuring-proxysql-query-routing-readwrite-splitting-and-connection-caching","status":"publish","type":"post","link":"https:\/\/cpanelfree.com\/blog\/configuring-proxysql-query-routing-readwrite-splitting-and-connection-caching\/","title":{"rendered":"Configuring ProxySQL Query Routing, Read\/Write Splitting, and Connection Caching"},"content":{"rendered":"<p>Enterprise relational database clusters frequently hit performance walls not because the underlying storage engines lack raw compute, but because client connection churn, unsegregated query paths, and thread contention overwhelm primary database nodes. In high-traffic environments, decoupling application database drivers from physical backend topologies using an intelligent layer-7 database proxy is the gold standard for achieving horizontal read scalability and sub-millisecond query delivery. By deploying an optimized ProxySQL layer on <a href=\"https:\/\/cpanelfree.com\">CpanelFree<\/a> high-performance infrastructure, systems engineers can transparently implement dynamic read\/write splitting, sub-microsecond connection multiplexing, and in-memory query result caching without altering a single line of application source code.<\/p>\n<p><!-- more --><\/p>\n<h2 style=\"color:#38bdf8;font-size:24px;margin-top:32px;margin-bottom:16px\">What is ProxySQL Read\/Write Splitting and Query Routing?<\/h2>\n<div style=\"background:#1e293b;border:1px solid #334155;border-left:4px solid #10b981;padding:16px 20px;border-radius:6px;margin:20px 0;color:#e2e8f0;font-size:15px;line-height:1.6\">\n  <strong style=\"color:#10b981\">Direct Answer:<\/strong> A <strong>ProxySQL read write split configuration<\/strong> is an intelligent Layer-7 database proxy architecture that inspects incoming SQL traffic in real time, automatically routing data-modifying queries (INSERT, UPDATE, DELETE) to primary writer hostgroups while directing analytical and idempotent read queries (SELECT) across healthy read-replica hostgroups with millisecond-level connection caching.\n<\/div>\n<p>Unlike basic Layer-4 TCP balancers (such as HAProxy in raw stream mode) that merely balance incoming socket connections across backend endpoints, ProxySQL operates with deep MySQL protocol intelligence. It continuously analyzes SQL statement syntax, abstracts backend connection pools from client threads, monitors replication lag, and enforces fine-grained traffic policies at line rate. This architectural separation resolves three critical database scaling challenges:<\/p>\n<ul style=\"color:#cbd5e1;line-height:1.8;padding-left:24px\">\n<li><strong style=\"color:#38bdf8\">Thundering Herd Connection Overhead:<\/strong> Each direct MySQL connection consumes substantial memory (default thread stack, per-connection buffers, and OS descriptors). ProxySQL enables tens of thousands of client frontend connections to share a compact, persistent pool of backend connections via multiplexing.<\/li>\n<li><strong style=\"color:#38bdf8\">Application Coupling:<\/strong> Traditional read\/write splitting requires application frameworks to maintain separate database connection handles (e.g., master vs. slave database pools). ProxySQL centralizes this logic into regular-expression query rules, decoupling infrastructure topology from software codebases.<\/li>\n<li><strong style=\"color:#38bdf8\">Failover and High Availability:<\/strong> During master node failovers or replica maintenance, ProxySQL dynamically repoints traffic without throwing application connection termination errors, handling transient disconnects gracefully.<\/li>\n<\/ul>\n<div style=\"background:#1e293b;border-left:4px solid #38bdf8;padding:16px 20px;margin:24px 0;border-radius:0 8px 8px 0;color:#e2e8f0\">\n  <strong style=\"color:#38bdf8\">Architecture Note:<\/strong> ProxySQL implements a three-tier configuration runtime: <em style=\"color:#38bdf8\">RUNTIME<\/em> (active memory structures processing queries), <em style=\"color:#38bdf8\">MEMORY<\/em> (in-memory SQLite database accessible via the admin interface on port 6032), and <em style=\"color:#38bdf8\">DISK<\/em> (persisted SQLite database file or static configuration). Any configuration change modified via the SQLite interface must be explicitly loaded to runtime and saved to disk to survive restarts.<\/div>\n<h2 style=\"color:#38bdf8;font-size:24px;margin-top:32px;margin-bottom:16px\">ProxySQL Performance &amp; Architectural Comparison<\/h2>\n<p>Before examining concrete configuration directives, review how a tuned ProxySQL proxy deployment contrasts with legacy direct-to-database connections under high concurrent throughput:<\/p>\n<table style=\"width:100%;border-collapse:collapse;margin:24px 0;background:#1e293b;color:#e2e8f0;font-size:14px;border-radius:8px;overflow:hidden\">\n<thead style=\"background:#0f172a;color:#38bdf8\">\n<tr>\n<th style=\"padding:12px 16px;border-bottom:2px solid #334155;text-align:left\">Feature \/ Metric<\/th>\n<th style=\"padding:12px 16px;border-bottom:2px solid #334155;text-align:left\">Standard \/ Direct MySQL<\/th>\n<th style=\"padding:12px 16px;border-bottom:2px solid #334155;text-align:left\">Tuned ProxySQL Production<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td style=\"padding:12px 16px;border-bottom:1px solid #334155;font-weight:600\">Connection Handshake Latency<\/td>\n<td style=\"padding:12px 16px;border-bottom:1px solid #334155;color:#94a3b8\">15ms &#8211; 45ms per client thread (SSL + Auth)<\/td>\n<td style=\"padding:12px 16px;border-bottom:1px solid #334155;color:#10b981;font-weight:600\">&lt; 0.8ms (Backend Pool Multiplexing)<\/td>\n<\/tr>\n<tr>\n<td style=\"padding:12px 16px;border-bottom:1px solid #334155;font-weight:600\">Maximum Concurrent Frontend Clients<\/td>\n<td style=\"padding:12px 16px;border-bottom:1px solid #334155;color:#94a3b8\">Limited by `max_connections` (typically 500-1,500)<\/td>\n<td style=\"padding:12px 16px;border-bottom:1px solid #334155;color:#10b981;font-weight:600\">10,000+ active client sockets<\/td>\n<\/tr>\n<tr>\n<td style=\"padding:12px 16px;border-bottom:1px solid #334155;font-weight:600\">Read\/Write Separation Method<\/td>\n<td style=\"padding:12px 16px;border-bottom:1px solid #334155;color:#94a3b8\">Hardcoded application-level connection routing<\/td>\n<td style=\"padding:12px 16px;border-bottom:1px solid #334155;color:#10b981;font-weight:600\">Transparent Layer-7 Regex &amp; Digest Query Rules<\/td>\n<\/tr>\n<tr>\n<td style=\"padding:12px 16px;border-bottom:1px solid #334155;font-weight:600\">Replication Lag Management<\/td>\n<td style=\"padding:12px 16px;border-bottom:1px solid #334155;color:#94a3b8\">Manual monitoring or app-level replica shedding<\/td>\n<td style=\"padding:12px 16px;border-bottom:1px solid #334155;color:#10b981;font-weight:600\">Automated host shunning when `max_lag_ms` breached<\/td>\n<\/tr>\n<tr>\n<td style=\"padding:12px 16px;border-bottom:1px solid #334155;font-weight:600\">Repetitive Query Caching<\/td>\n<td style=\"padding:12px 16px;border-bottom:1px solid #334155;color:#94a3b8\">External Redis\/Memcached cluster required<\/td>\n<td style=\"padding:12px 16px;border-bottom:1px solid #334155;color:#10b981;font-weight:600\">In-Memory Native ProxySQL Query Cache with TTL<\/td>\n<\/tr>\n<tr>\n<td style=\"padding:12px 16px;border-bottom:1px solid #334155;font-weight:600\">Master Failover Impact<\/td>\n<td style=\"padding:12px 16px;border-bottom:1px solid #334155;color:#94a3b8\">Application throws 2006\/2013 connection drop errors<\/td>\n<td style=\"padding:12px 16px;border-bottom:1px solid #334155;color:#10b981;font-weight:600\">Seamless traffic pause and replay to promoted node<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h2 style=\"color:#38bdf8;font-size:24px;margin-top:32px;margin-bottom:16px\">Linux Kernel &amp; Operating System Tuning for ProxySQL<\/h2>\n<p>ProxySQL is an event-driven, multi-threaded C++ engine utilizing non-blocking epoll sockets. Under enterprise workloads handling thousands of concurrent transactions, the Linux kernel must be tuned to prevent TCP socket exhaustion, SYN queue drops, and file descriptor starvation.<\/p>\n<p>Create a dedicated sysctl configuration file at <code style=\"color:#38bdf8\">\/etc\/sysctl.d\/99-proxysql-networking.conf<\/code> with the following production-grade kernel parameters:<\/p>\n<pre><code style=\"background:#0f172a;color:#38bdf8;padding:16px;border-radius:8px;display:block;font-family:monospace;font-size:13px;line-height:1.6\"># \/etc\/sysctl.d\/99-proxysql-networking.conf\n# Production Kernel Network Optimization for ProxySQL Database Gateways\n\n# Maximize socket listen backlog for burst connections\nnet.core.somaxconn = 65535\nnet.ipv4.tcp_max_syn_backlog = 65535\n\n# Optimize ephemeral port range for massive backend connection pools\nnet.ipv4.ip_local_port_range = 1024 65535\n\n# Enable fast reuse of TIME_WAIT sockets for outgoing connections\nnet.ipv4.tcp_tw_reuse = 1\n\n# Reduce TCP keepalive parameters to rapidly detect dead backend nodes\nnet.ipv4.tcp_keepalive_time = 300\nnet.ipv4.tcp_keepalive_intvl = 15\nnet.ipv4.tcp_keepalive_probes = 5\n\n# TCP buffer sizing for high throughput (min, default, max in bytes)\nnet.ipv4.tcp_rmem = 4096 87380 16777216\nnet.ipv4.tcp_wmem = 4096 65536 16777216\nnet.core.rmem_max = 16777216\nnet.core.wmem_max = 16777216\n\n# Protect against SYN flood attacks while maintaining responsiveness\nnet.ipv4.tcp_syncookies = 1\nnet.ipv4.tcp_fin_timeout = 15\n\n# Increase system-wide file descriptor limit\nfs.file-max = 2097152<\/code><\/pre>\n<p>Apply the parameters immediately without rebooting:<\/p>\n<pre><code style=\"background:#0f172a;color:#38bdf8;padding:16px;border-radius:8px;display:block;font-family:monospace;font-size:13px;line-height:1.6\">sudo sysctl --system<\/code><\/pre>\n<p>Next, configure process limits for the ProxySQL systemd service to prevent <code style=\"color:#38bdf8\">EMFILE: Too many open files<\/code> errors. Create a systemd drop-in override at <code style=\"color:#38bdf8\">\/etc\/systemd\/system\/proxysql.service.d\/override.conf<\/code>:<\/p>\n<pre><code style=\"background:#0f172a;color:#38bdf8;padding:16px;border-radius:8px;display:block;font-family:monospace;font-size:13px;line-height:1.6\"># \/etc\/systemd\/system\/proxysql.service.d\/override.conf\n[Service]\nLimitNOFILE=1048576\nLimitNPROC=524288\nLimitMEMLOCK=infinity\nRestart=always\nRestartSec=5s<\/code><\/pre>\n<p>Reload systemd daemon configurations and restart ProxySQL:<\/p>\n<pre><code style=\"background:#0f172a;color:#38bdf8;padding:16px;border-radius:8px;display:block;font-family:monospace;font-size:13px;line-height:1.6\">sudo systemctl daemon-reload\nsudo systemctl restart proxysql<\/code><\/pre>\n<h2 style=\"color:#38bdf8;font-size:24px;margin-top:32px;margin-bottom:16px\">Production ProxySQL Global Configuration File (\/etc\/proxysql.cnf)<\/h2>\n<p>The global configuration file establishes the administrative socket, daemon threading model, and memory buffers. The admin interface is hosted by default on TCP port <code style=\"color:#38bdf8\">6032<\/code>, while incoming application MySQL traffic binds to TCP port <code style=\"color:#38bdf8\">6033<\/code>.<\/p>\n<pre><code style=\"background:#0f172a;color:#38bdf8;padding:16px;border-radius:8px;display:block;font-family:monospace;font-size:13px;line-height:1.6\"># \/etc\/proxysql.cnf\n# Enterprise ProxySQL Configuration for High-Concurrency Read\/Write Splitting\n\ndatadir=\"\/var\/lib\/proxysql\"\n\nadmin_variables={\n    admin_credentials=\"admin:CpanelFree_Admin_Sec2026;radmin:CpanelFree_RAdmin_Sec2026\"\n    mysql_ifaces=\"127.0.0.1:6032;\/var\/run\/proxysql\/proxysql_admin.sock\"\n    refresh_interval=2000\n}\n\nmysql_variables={\n    threads=8                                  # Match dedicated CPU physical cores\n    max_connections=10000                      # Frontend client connection ceiling\n    default_query_delay=0\n    default_query_timeout=3600000              # 1 hour timeout protection\n    have_compress=true\n    poll_timeout=2000                          # Epoll timeout in microseconds\n    interfaces=\"0.0.0.0:6033;\/var\/run\/proxysql\/proxysql.sock\"\n    default_schema=\"information_schema\"\n    stacksize=1048576\n    server_version=\"8.0.36-ProxySQL\"\n    connect_timeout_server=3000                # Timeout connecting to MySQL backends (ms)\n    monitor_history=600000                     # 10 minutes monitor telemetry\n    monitor_connect_interval=60000\n    monitor_ping_interval=10000\n    monitor_read_only_interval=1500\n    monitor_read_only_timeout=800\n    ping_interval_server_msec=120000\n    ping_timeout_server=500\n    commands_stats=true\n    sessions_sort=true\n    connect_retries_on_failure=10\n    query_cache_size_MB=256                    # In-memory query result cache pool\n}<\/code><\/pre>\n<h2 style=\"color:#38bdf8;font-size:24px;margin-top:32px;margin-bottom:16px\">Configuring Hostgroups, Servers, and Replication Awareness<\/h2>\n<p>ProxySQL organizes backend database nodes into logical numeric entities known as <strong>Hostgroups<\/strong>. In standard Master-Replica topologies, we assign:<\/p>\n<ul style=\"color:#cbd5e1;line-height:1.8;padding-left:24px\">\n<li><strong style=\"color:#38bdf8\">Hostgroup 10:<\/strong> Primary Master (Writer) node(s). All data mutation statements target this hostgroup.<\/li>\n<li><strong style=\"color:#38bdf8\">Hostgroup 20:<\/strong> Read Replica (Reader) nodes. All read queries target this group for load distribution.<\/li>\n<\/ul>\n<p>Connect to the ProxySQL administrative interface using the MySQL client:<\/p>\n<pre><code style=\"background:#0f172a;color:#38bdf8;padding:16px;border-radius:8px;display:block;font-family:monospace;font-size:13px;line-height:1.6\">mysql -u admin -pCpanelFree_Admin_Sec2026 -h 127.0.0.1 -P 6032 --prompt='ProxySQL Admin&gt; '<\/code><\/pre>\n<p>Execute the following SQL script to define the backend topology, configure replication lag thresholds, and set up health checks:<\/p>\n<pre><code style=\"background:#0f172a;color:#38bdf8;padding:16px;border-radius:8px;display:block;font-family:monospace;font-size:13px;line-height:1.6\">-- 1. Purge existing staging server definitions\nDELETE FROM mysql_servers;\n\n-- 2. Register Primary Master into Hostgroup 10 (Writer)\nINSERT INTO mysql_servers (\n    hostgroup_id, hostname, port, status, weight, compression, max_connections, max_replication_lag, use_ssl\n) VALUES (\n    10, '192.168.10.101', 3306, 'ONLINE', 1000, 0, 1000, 0, 1\n);\n\n-- 3. Register Read Replicas into Hostgroup 20 (Readers)\nINSERT INTO mysql_servers (\n    hostgroup_id, hostname, port, status, weight, compression, max_connections, max_replication_lag, use_ssl\n) VALUES \n(20, '192.168.10.102', 3306, 'ONLINE', 100, 0, 1000, 5, 1),\n(20, '192.168.10.103', 3306, 'ONLINE', 100, 0, 1000, 5, 1),\n(20, '192.168.10.104', 3306, 'ONLINE', 100, 0, 1000, 5, 1);\n\n-- 4. Enable Dynamic Replication Hostgroups (Automatic read_only tracking)\n-- If read_only=0 on a node, ProxySQL places it in writer_hostgroup (10).\n-- If read_only=1 on a node, ProxySQL places it in reader_hostgroup (20).\nDELETE FROM mysql_replication_hostgroups;\nINSERT INTO mysql_replication_hostgroups (\n    writer_hostgroup, reader_hostgroup, check_type, comment\n) VALUES (\n    10, 20, 'read_only', 'Automated Master\/Replica Read-Only State Tracker'\n);\n\n-- 5. Commit server topology to RUNTIME and persist to DISK\nLOAD MYSQL SERVERS TO RUNTIME;\nSAVE MYSQL SERVERS TO DISK;<\/code><\/pre>\n<div style=\"background:#1e293b;border-left:4px solid #f59e0b;padding:16px 20px;margin:24px 0;border-radius:0 8px 8px 0;color:#e2e8f0\">\n  <strong style=\"color:#f59e0b\">Replication Lag Safety:<\/strong> Setting <code style=\"color:#f59e0b\">max_replication_lag=5<\/code> instructs ProxySQL to inspect <code style=\"color:#f59e0b\">Seconds_Behind_Master<\/code> on replicas every second. If replica lag exceeds 5 seconds, ProxySQL automatically changes the node&#8217;s status to <code style=\"color:#f59e0b\">SHUNNED<\/code>, diverting read traffic to the remaining healthy replicas to guarantee read consistency.<\/div>\n<h2 style=\"color:#38bdf8;font-size:24px;margin-top:32px;margin-bottom:16px\">Configuring Application Users and Credentials<\/h2>\n<p>ProxySQL must be aware of application users so it can authenticate client sessions and match credentials when opening backend connections. Define the application user and configure default hostgroup routing:<\/p>\n<pre><code style=\"background:#0f172a;color:#38bdf8;padding:16px;border-radius:8px;display:block;font-family:monospace;font-size:13px;line-height:1.6\">-- Register Application User\nDELETE FROM mysql_users WHERE username='app_production';\n\nINSERT INTO mysql_users (\n    username, password, active, default_hostgroup, default_schema, transaction_persistent, fast_forward\n) VALUES (\n    'app_production', 'Str0ng_Pr0d_Db_P@ss2026', 1, 10, 'app_db', 1, 0\n);\n\n-- Configure Monitor User for Heartbeat &amp; Replication Telemetry\nSET admin-stats_credentials='monitor:Mon1t0r_Sec_P@ss2026';\nSET mysql-monitor_username='proxysql_monitor';\nSET mysql-monitor_password='Mon1t0r_Sec_P@ss2026';\n\n-- Commit Users to RUNTIME and DISK\nLOAD MYSQL USERS TO RUNTIME;\nSAVE MYSQL USERS TO DISK;\nLOAD ADMIN VARIABLES TO RUNTIME;\nSAVE ADMIN VARIABLES TO DISK;\nLOAD MYSQL VARIABLES TO RUNTIME;\nSAVE MYSQL VARIABLES TO DISK;<\/code><\/pre>\n<div style=\"background:#1e293b;border-left:4px solid #38bdf8;padding:16px 20px;margin:24px 0;border-radius:0 8px 8px 0;color:#e2e8f0\">\n  <strong style=\"color:#38bdf8\">Crucial Parameter:<\/strong> Setting <code style=\"color:#38bdf8\">transaction_persistent=1<\/code> ensures that once a client issues a <code style=\"color:#38bdf8\">BEGIN<\/code> or <code style=\"color:#38bdf8\">START TRANSACTION<\/code>, all subsequent queries within that session remain pinned to the writer hostgroup (10) until a <code style=\"color:#38bdf8\">COMMIT<\/code> or <code style=\"color:#38bdf8\">ROLLBACK<\/code> occurs. This prevents catastrophic read-your-own-writes inconsistencies inside transactional blocks.<\/div>\n<h2 style=\"color:#38bdf8;font-size:24px;margin-top:32px;margin-bottom:16px\">Advanced Query Routing and Read\/Write Splitting Rules<\/h2>\n<p>ProxySQL processes queries through the <code style=\"color:#38bdf8\">mysql_query_rules<\/code> table in ascending order of <code style=\"color:#38bdf8\">rule_id<\/code>. When a query arrives, ProxySQL checks the rule chain. If a rule matches and specifies <code style=\"color:#38bdf8\">apply=1<\/code>, rule evaluation halts, and the query routes to the target hostgroup.<\/p>\n<p>A production-ready read\/write splitting rule chain must implement four fundamental protections:<\/p>\n<ol style=\"color:#cbd5e1;line-height:1.8;padding-left:24px\">\n<li><strong style=\"color:#38bdf8\">Locking Read Protection:<\/strong> Divert <code style=\"color:#38bdf8\">SELECT ... FOR UPDATE<\/code> and <code style=\"color:#38bdf8\">LOCK IN SHARE MODE<\/code> to the Master (Hostgroup 10).<\/li>\n<li><strong style=\"color:#38bdf8\">Default Writer Anchor:<\/strong> Ensure non-SELECT statements (INSERT, UPDATE, DELETE, REPLACE, DDL) route to Hostgroup 10.<\/li>\n<li><strong style=\"color:#38bdf8\">Read Offloading:<\/strong> Route standard read-only <code style=\"color:#38bdf8\">SELECT<\/code> statements to the Reader pool (Hostgroup 20).<\/li>\n<li><strong style=\"color:#38bdf8\">Selective In-Memory Result Caching:<\/strong> Cache idempotent, high-frequency lookup queries directly in ProxySQL RAM with a tailored TTL.<\/li>\n<\/ol>\n<p>Execute the following SQL script to install this enterprise rule set:<\/p>\n<pre><code style=\"background:#0f172a;color:#38bdf8;padding:16px;border-radius:8px;display:block;font-family:monospace;font-size:13px;line-height:1.6\">-- Clear old rules\nDELETE FROM mysql_query_rules;\n\n-- Rule 10: Fast-track and protect SELECT ... FOR UPDATE \/ LOCK IN SHARE MODE (Send to Master)\nINSERT INTO mysql_query_rules (\n    rule_id, active, match_pattern, destination_hostgroup, apply, comment\n) VALUES (\n    10, 1, '^SELECT.*FOR UPDATE|^SELECT.*LOCK IN SHARE MODE', 10, 1, 'Locking reads routed to Master'\n);\n\n-- Rule 20: Cache high-frequency, read-heavy catalog\/metadata queries in ProxySQL RAM (TTL: 3000ms)\nINSERT INTO mysql_query_rules (\n    rule_id, active, match_pattern, destination_hostgroup, cache_ttl, apply, comment\n) VALUES (\n    20, 1, '^SELECT.*FROM `system_settings`|^SELECT.*FROM `global_config`', 20, 3000, 1, 'In-memory cached lookup queries'\n);\n\n-- Rule 30: Route all standard SELECT queries to Reader Hostgroup (Hostgroup 20)\nINSERT INTO mysql_query_rules (\n    rule_id, active, match_pattern, destination_hostgroup, apply, comment\n) VALUES (\n    30, 1, '^SELECT .*', 20, 1, 'Standard reads routed to Replicas'\n);\n\n-- Rule 40: Explicit fallback for all write and data modification operations (Hostgroup 10)\nINSERT INTO mysql_query_rules (\n    rule_id, active, match_pattern, destination_hostgroup, apply, comment\n) VALUES (\n    40, 1, '.*', 10, 1, 'Catch-all writes, DDL, and transactions routed to Master'\n);\n\n-- Commit rules to RUNTIME and DISK\nLOAD MYSQL QUERY RULES TO RUNTIME;\nSAVE MYSQL QUERY RULES TO DISK;<\/code><\/pre>\n<h2 style=\"color:#38bdf8;font-size:24px;margin-top:32px;margin-bottom:16px\">Connection Caching and Multiplexing Optimization<\/h2>\n<p>ProxySQL connection multiplexing is its most powerful performance mechanism. In standard setups, when 2,000 PHP-FPM or Node.js workers connect, MySQL spawns 2,000 execution threads. With ProxySQL multiplexing enabled, those 2,000 client sessions are managed inside an epoll event loop and mapped onto a compact pool of just 30 to 50 active backend connections.<\/p>\n<p>Multiplexing operates at the individual statement boundary. Between queries, a backend connection is released back into the pool. However, certain SQL actions can temporarily disable multiplexing for a session (known as multiplexing inhibitors):<\/p>\n<ul style=\"color:#cbd5e1;line-height:1.8;padding-left:24px\">\n<li>Setting session variables (e.g., <code style=\"color:#38bdf8\">SET @my_var = 1;<\/code> or <code style=\"color:#38bdf8\">SET sql_mode = ...<\/code>)<\/li>\n<li>Creating temporary tables (<code style=\"color:#38bdf8\">CREATE TEMPORARY TABLE ...<\/code>)<\/li>\n<li>Executing <code style=\"color:#38bdf8\">LOCK TABLES<\/code><\/li>\n<li>Uncommitted active transactions<\/li>\n<\/ul>\n<p>To maximize multiplexing efficiency and prevent unnecessary connection pinning, configure ProxySQL to ignore non-destructive session variables:<\/p>\n<pre><code style=\"background:#0f172a;color:#38bdf8;padding:16px;border-radius:8px;display:block;font-family:monospace;font-size:13px;line-height:1.6\">-- Whitelist benign session variables to preserve connection multiplexing\nINSERT INTO mysql_multiplexing_variables (variable, status) VALUES\n('autocommit', 'IGNORE'),\n('sql_mode', 'IGNORE'),\n('character_set_client', 'IGNORE'),\n('character_set_connection', 'IGNORE'),\n('character_set_results', 'IGNORE'),\n('collation_connection', 'IGNORE'),\n('time_zone', 'IGNORE');\n\nLOAD MYSQL VARIABLES TO RUNTIME;\nSAVE MYSQL VARIABLES TO DISK;<\/code><\/pre>\n<h2 style=\"color:#38bdf8;font-size:24px;margin-top:32px;margin-bottom:16px\">Real-Time Telemetry and Verification Benchmarks<\/h2>\n<p>Once traffic flows through port 6033, verify that query routing, server health checks, and connection pools function as intended using ProxySQL&#8217;s built-in statistical tables:<\/p>\n<h3 style=\"color:#38bdf8;font-size:18px;margin-top:20px;margin-bottom:12px\">1. Inspect Connection Pool Utilization<\/h3>\n<pre><code style=\"background:#0f172a;color:#38bdf8;padding:16px;border-radius:8px;display:block;font-family:monospace;font-size:13px;line-height:1.6\">SELECT hostgroup, srv_host, srv_port, status, ConnUsed, ConnFree, ConnOK, ConnERR, Queries \nFROM stats_mysql_connection_pool \nORDER BY hostgroup, srv_host;<\/code><\/pre>\n<p>In a healthy deployment, <code style=\"color:#10b981\">ConnFree<\/code> stays consistently positive (ready pooled connections), and <code style=\"color:#10b981\">Queries<\/code> increases across Hostgroup 20 for reads and Hostgroup 10 for writes.<\/p>\n<h3 style=\"color:#38bdf8;font-size:18px;margin-top:20px;margin-bottom:12px\">2. Monitor Query Rule Hits and Cache Efficiency<\/h3>\n<pre><code style=\"background:#0f172a;color:#38bdf8;padding:16px;border-radius:8px;display:block;font-family:monospace;font-size:13px;line-height:1.6\">SELECT rule_id, hits, comment \nFROM stats_mysql_query_rules \nORDER BY hits DESC;<\/code><\/pre>\n<p>Review the <code style=\"color:#38bdf8\">hits<\/code> counter to confirm that Rule 30 (SELECTs to Replicas) and Rule 40 (Writes to Master) increment as expected. Rule 20 will show the volume of queries satisfied entirely from RAM without touching backend MySQL disk or compute.<\/p>\n<h2 style=\"color:#38bdf8;font-size:24px;margin-top:32px;margin-bottom:16px\">Frequently Asked Questions<\/h2>\n<details style=\"background:#1e293b;border:1px solid #334155;border-radius:8px;padding:14px;margin-bottom:12px\">\n<summary style=\"cursor:pointer;font-weight:600;color:#38bdf8\">How does ProxySQL handle transaction consistency during read\/write splitting?<\/summary>\n<p style=\"margin-top:10px;color:#cbd5e1\">When <code>transaction_persistent=1<\/code> is enabled in <code>mysql_users<\/code>, ProxySQL automatically tracks session transaction state. When an explicit <code>START TRANSACTION<\/code> or <code>BEGIN<\/code> is issued, all queries within that transaction are pinned to the primary master hostgroup regardless of standard regex read rules. Once <code>COMMIT<\/code> or <code>ROLLBACK<\/code> completes, ProxySQL resumes normal read\/write splitting.<\/p>\n<\/details>\n<details style=\"background:#1e293b;border:1px solid #334155;border-radius:8px;padding:14px;margin-bottom:12px\">\n<summary style=\"cursor:pointer;font-weight:600;color:#38bdf8\">What happens if a read replica encounters severe replication lag?<\/summary>\n<p style=\"margin-top:10px;color:#cbd5e1\">ProxySQL continuously probes replica lag using its internal monitor thread. If a replica&#8217;s lag exceeds the configured <code>max_replication_lag<\/code> (e.g., 5 seconds), ProxySQL marks that server as <code>SHUNNED<\/code>. Query traffic is instantly redistributed among remaining healthy replicas. Once the lagged replica catches up below the threshold, it is automatically returned to <code>ONLINE<\/code> status.<\/p>\n<\/details>\n<details style=\"background:#1e293b;border:1px solid #334155;border-radius:8px;padding:14px;margin-bottom:12px\">\n<summary style=\"cursor:pointer;font-weight:600;color:#38bdf8\">Can ProxySQL cache query results like Redis or Memcached?<\/summary>\n<p style=\"margin-top:10px;color:#cbd5e1\">Yes. ProxySQL features a built-in, in-memory query result cache configured via the <code>cache_ttl<\/code> parameter in <code>mysql_query_rules<\/code>. For repetitive, identical SELECT statements matching a configured pattern, ProxySQL serves results directly from memory in microseconds without dispatching requests to backend database servers.<\/p>\n<\/details>\n<details style=\"background:#1e293b;border:1px solid #334155;border-radius:8px;padding:14px;margin-bottom:12px\">\n<summary style=\"cursor:pointer;font-weight:600;color:#38bdf8\">Do I need to modify my application database code to use ProxySQL?<\/summary>\n<p style=\"margin-top:10px;color:#cbd5e1\">No. ProxySQL speaks the native MySQL wire protocol. You simply point your application database connection host and port to ProxySQL (typically <code>127.0.0.1:6033<\/code>). All query parsing, routing to writer or reader nodes, connection pooling, and caching occur transparently at Layer 7.<\/p>\n<\/details>\n<div style=\"background:linear-gradient(135deg, #0f172a 0%, #1e293b 100%);border:1px solid #334155;border-radius:12px;padding:32px;margin:40px 0;text-align:center\">\n<h3 style=\"color:#ffffff;margin-top:0;font-size:22px\">Ready to Deploy High-Performance Infrastructure?<\/h3>\n<p style=\"color:#cbd5e1;font-size:16px;line-height:1.6;max-width:680px;margin:12px auto 24px auto\">Experience blazing-fast NVMe storage, unmetered bandwidth, and enterprise LiteSpeed caching on CpanelFree.<\/p>\n<p>  <a href=\"https:\/\/cpanelfree.com\" style=\"background:#38bdf8;color:#0f172a;font-weight:700;padding:12px 28px;border-radius:6px;text-decoration:none;display:inline-block;font-size:15px\">Get Started with Free Cloud Hosting &rarr;<\/a>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>Master enterprise ProxySQL query routing, seamless read\/write splitting, and high-concurrency connection caching. Scale MySQL throughput without application refactoring.<\/p>\n","protected":false},"author":1,"featured_media":4619,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[57,177,87,101],"class_list":["post-4620","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-web-hosting-news","tag-almalinux","tag-databases-performance","tag-devops","tag-sysadmin"],"_links":{"self":[{"href":"https:\/\/cpanelfree.com\/blog\/wp-json\/wp\/v2\/posts\/4620","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/cpanelfree.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/cpanelfree.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/cpanelfree.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/cpanelfree.com\/blog\/wp-json\/wp\/v2\/comments?post=4620"}],"version-history":[{"count":0,"href":"https:\/\/cpanelfree.com\/blog\/wp-json\/wp\/v2\/posts\/4620\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/cpanelfree.com\/blog\/wp-json\/wp\/v2\/media\/4619"}],"wp:attachment":[{"href":"https:\/\/cpanelfree.com\/blog\/wp-json\/wp\/v2\/media?parent=4620"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/cpanelfree.com\/blog\/wp-json\/wp\/v2\/categories?post=4620"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/cpanelfree.com\/blog\/wp-json\/wp\/v2\/tags?post=4620"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}