ProxySQL Complete Cheat Sheet
A quick reference for all essential ProxySQL SQL commands, variables, and patterns. Bookmark this page for fast access to commands you use regularly.
Connection Commands
BASH — Connection
# Connect to Admin interface
mysql -u admin -padmin -h 127.0.0.1 -P 6032 --prompt="ProxySQL> "
# Connect as app user through ProxySQL
mysql -u appuser -ppassword -h 127.0.0.1 -P 6033
# Connect to Admin with SSL
mysql -u admin -padmin -h 127.0.0.1 -P 6032 --ssl-mode=REQUIRED
MySQL Servers
SQL — MySQL Servers
-- Add server
INSERT INTO mysql_servers (hostgroup_id, hostname, port, status, weight, max_connections, comment)
VALUES (10, '192.168.1.100', 3306, 'ONLINE', 1, 1000, 'Master');
-- List servers
SELECT hostgroup_id, hostname, port, status, weight FROM mysql_servers;
-- Change server status
UPDATE mysql_servers SET status='OFFLINE_SOFT' WHERE hostname='192.168.1.100';
UPDATE mysql_servers SET status='ONLINE' WHERE hostname='192.168.1.100';
-- Remove server
DELETE FROM mysql_servers WHERE hostname='192.168.1.100';
-- Apply
LOAD MYSQL SERVERS TO RUNTIME;
SAVE MYSQL SERVERS TO DISK;
-- View active servers
SELECT hostgroup_id, hostname, port, status, ConnUsed FROM runtime_mysql_servers;
MySQL Users
SQL — MySQL Users
-- Add user
INSERT INTO mysql_users (username, password, default_hostgroup, active, transaction_persistent)
VALUES ('appuser', 'password', 10, 1, 1);
-- List users
SELECT username, default_hostgroup, active, transaction_persistent FROM mysql_users;
-- Disable user
UPDATE mysql_users SET active=0 WHERE username='appuser';
-- Change default hostgroup
UPDATE mysql_users SET default_hostgroup=20 WHERE username='reports_user';
-- Apply
LOAD MYSQL USERS TO RUNTIME;
SAVE MYSQL USERS TO DISK;
Query Rules
SQL — Query Rules
-- Add rule: route SELECTs to replicas
INSERT INTO mysql_query_rules (rule_id, active, match_pattern, destination_hostgroup, apply, comment)
VALUES (1, 1, '^SELECT .* FOR UPDATE', 10, 1, 'Locking reads to master');
INSERT INTO mysql_query_rules (rule_id, active, match_pattern, destination_hostgroup, apply, comment)
VALUES (2, 1, '^SELECT', 20, 1, 'SELECTs to replicas');
-- Add blocking rule
INSERT INTO mysql_query_rules (rule_id, active, match_pattern, error_msg, apply)
VALUES (100, 1, '^DROP TABLE', 'Not allowed', 1);
-- Add caching rule
INSERT INTO mysql_query_rules (rule_id, active, match_pattern, cache_ttl, destination_hostgroup, apply)
VALUES (200, 1, 'SELECT .* FROM config', 60000, 20, 1);
-- View rules with hit counts
SELECT rule_id, hits, match_pattern, destination_hostgroup, cache_ttl
FROM stats.stats_mysql_query_rules ORDER BY rule_id;
-- Apply
LOAD MYSQL QUERY RULES TO RUNTIME;
SAVE MYSQL QUERY RULES TO DISK;
Global Variables
SQL — Global Variables
-- Common variables to check/set
SELECT variable_name, variable_value FROM global_variables
WHERE variable_name IN (
'mysql-max_connections',
'mysql-threads',
'mysql-monitor_username',
'mysql-monitor_password',
'mysql-monitor_ping_interval',
'mysql-monitor_read_only_interval',
'admin-admin_credentials',
'mysql-query_cache_size_MB'
);
-- Change a variable
UPDATE global_variables SET variable_value='50000'
WHERE variable_name='mysql-max_connections';
LOAD MYSQL VARIABLES TO RUNTIME;
SAVE MYSQL VARIABLES TO DISK;
Stats Quick Reference
SQL — Stats
-- Connection pool
SELECT hostgroup, srv_host, status, ConnUsed, ConnFree, Queries, Latency_us
FROM stats.stats_mysql_connection_pool;
-- Top queries
SELECT hostgroup, digest_text, count_star, avg_time
FROM stats.stats_mysql_query_digest ORDER BY count_star DESC LIMIT 10;
-- Active connections
SELECT user, hostgroup, command, time_ms, info
FROM stats.stats_mysql_processlist ORDER BY time_ms DESC;
-- Global counters
SELECT variable_name, variable_value FROM stats.stats_mysql_global
WHERE variable_name IN ('Questions','Slow_queries','Client_Connections_connected');
-- Monitor logs
SELECT hostname, port, read_only FROM monitor.mysql_server_read_only_log
ORDER BY time_start_us DESC LIMIT 5;
SELECT hostname, port, ping_success FROM monitor.mysql_server_ping_log
ORDER BY time_start_us DESC LIMIT 5;
Load and Save Commands
SQL — Load and Save
-- MySQL Servers
LOAD MYSQL SERVERS TO RUNTIME; SAVE MYSQL SERVERS TO DISK;
LOAD MYSQL SERVERS FROM RUNTIME; LOAD MYSQL SERVERS FROM DISK;
-- MySQL Users
LOAD MYSQL USERS TO RUNTIME; SAVE MYSQL USERS TO DISK;
-- Query Rules
LOAD MYSQL QUERY RULES TO RUNTIME; SAVE MYSQL QUERY RULES TO DISK;
-- MySQL Variables
LOAD MYSQL VARIABLES TO RUNTIME; SAVE MYSQL VARIABLES TO DISK;
-- Admin Variables
LOAD ADMIN VARIABLES TO RUNTIME; SAVE ADMIN VARIABLES TO DISK;
-- ProxySQL Servers (cluster)
LOAD PROXYSQL SERVERS TO RUNTIME; SAVE PROXYSQL SERVERS TO DISK;
-- Scheduler
LOAD SCHEDULER TO RUNTIME; SAVE SCHEDULER TO DISK;
Hostgroup Quick Setup
SQL — Hostgroup Setup
-- Standard Master-Replica setup
INSERT INTO mysql_replication_hostgroups (writer_hostgroup, reader_hostgroup, check_type, comment)
VALUES (10, 20, 'read_only', 'R/W Split');
-- Group Replication / InnoDB Cluster
INSERT INTO mysql_group_replication_hostgroups
(writer_hostgroup, backup_writer_hostgroup, reader_hostgroup, offline_hostgroup,
active, max_writers, writer_is_also_reader, max_transactions_behind)
VALUES (10, 30, 20, 40, 1, 1, 0, 0);
-- Galera / PXC
INSERT INTO mysql_galera_hostgroups
(writer_hostgroup, backup_writer_hostgroup, reader_hostgroup, offline_hostgroup,
active, max_writers, writer_is_also_reader, max_transactions_behind)
VALUES (10, 30, 20, 40, 1, 1, 1, 0);
LOAD MYSQL SERVERS TO RUNTIME;
SAVE MYSQL SERVERS TO DISK;
Admin Commands
SQL — Admin Commands
PROXYSQL FLUSH LOGS; -- Flush all log files
PROXYSQL RESTART; -- Restart ProxySQL threads (no downtime)
PROXYSQL SHUTDOWN; -- Full shutdown
PROXYSQL KILL SESSION 42; -- Kill session by ID
SHOW TABLES; -- Show Admin tables
SHOW DATABASES; -- Show Admin databases
SELECT @@version; -- ProxySQL version
Page Index
| # | Page | Topic |
|---|---|---|
| 1 | Introduction & Architecture | What is ProxySQL, components, ports |
| 2 | Installation | RHEL, CentOS, Ubuntu, Debian |
| 3 | Admin Interface | Port 6032, databases, tables, commands |
| 4 | Runtime vs Memory vs Disk | Three-layer config, Load/Save pattern |
| 5 | Config File | proxysql.cnf deep dive |
| 6 | MySQL Backend Servers | mysql_servers table, status values |
| 7 | Hostgroups | Design patterns, replication hostgroups |
| 8 | MySQL Users | mysql_users, passwords, transaction_persistent |
| 9 | Query Rules | Full column reference, examples, regex |
| 10 | Read/Write Split | Complete step-by-step setup |
| 11 | Monitor Setup | Monitor user, health checks, intervals |
| 12 | Connection Pooling | Multiplexing, pool variables, stats |
| 13 | Stats & Monitoring | stats database tables, global counters |
| 14 | Query Digest | Slow queries, normalization, analysis |
| 15 | ProxySQL Cluster | Multi-node setup, config sync |
| 16 | Query Cache | TTL, cache rules, hit ratio |
| 17 | Automatic Failover | Detection, master failover, orchestrator |
| 18 | MySQL Replication | Master-Replica + ProxySQL full setup |
| 19 | Group Replication | MGR single-primary + ProxySQL |
| 20 | Galera Cluster | PXC + ProxySQL, wsrep monitoring |
| 21 | SSL/TLS | Frontend, backend, per-user SSL |
| 22 | Performance Tuning | Threads, connections, compression |
| 23 | Query Rewriting | replace_pattern, hints, table rename |
| 24 | Traffic Mirroring | mirror_hostgroup, shadow queries |
| 25 | Backup & Restore | SQLite backup, SQL export, migration |
| 26 | Upgrade | Safe upgrade, zero-downtime, rollback |
| 27 | Troubleshooting | Common issues, diagnostics, fixes |
| 28 | Logging | Error log, query log, audit log |
| 29 | REST API & Prometheus | Metrics, Grafana, Alertmanager |
| 30 | Query Firewall | Block queries, whitelist, per-user rules |
| 31 | InnoDB Cluster | MySQL InnoDB Cluster + ProxySQL |
| 32 | Cheat Sheet | This page — complete quick reference |