MaxScale is MariaDB’s database proxy — it terminates client connections, parses SQL, and routes statements to the correct backend depending on whether they read or write, where the writeable node lives, and what the application asked for. This article is the production configuration we deploy when a client runs a MariaDB primary with replicas or a Galera cluster and needs the application to keep going through node loss without a code change. We will install MaxScale, define services and listeners, point it at a backend, and verify the routing logic is doing what we expect.
How to verify
After installation, the maxctrl command line talks to the running MaxScale and shows the live state of every server, service, and listener.
sudo systemctl status maxscale
sudo maxctrl list servers
sudo maxctrl list services
sudo maxctrl list listeners
sudo maxctrl show server db01
mysql -h maxscale-host -P 4006 -u app -p -e "SELECT @@hostname, @@read_only;"
maxctrl list servers must show every backend in state Master / Slave / Synced (for Galera). A backend in Down or Auth Failed is unreachable to MaxScale and traffic is not flowing to it.
What’s happening
MaxScale has four moving parts. A server is a backend MariaDB instance MaxScale knows about. A monitor watches a set of servers and assigns roles — mariadbmon for async replication topologies, galeramon for Galera. A service wires a routing module to a set of servers — readwritesplit is the production read/write splitter, readconnroute is a simpler connection-balancing router. A listener is the TCP port the service is exposed on; clients connect to the listener, not to MariaDB directly.
For a primary-replica topology, mariadbmon discovers which node has read_only=OFF, marks it Master, marks the others Slave, and republishes that view continuously. readwritesplit parses each statement: writes and statements inside an explicit transaction go to the Master, simple reads go to a Slave. If the primary disappears, mariadbmon can be configured to promote a replica automatically — auto_failover=true — and the listener stays up the whole time.
For Galera, galeramon watches wsrep_local_state_comment and only routes to nodes in Synced state. Donors during SST are pulled out of rotation; joiners catching up via IST are not used until they reach Synced. This is why MaxScale in front of Galera is more than a load balancer — it has the SQL-aware awareness to keep a node out of rotation precisely while it would corrupt the read set.
The procedure
-
Install MaxScale from the official MariaDB repository — the distribution package is often two major versions behind and missing the
mariadbmonreconciliation we depend on.curl -fsSL https://dlm.mariadb.com/enterprise-release-helpers/mariadb_es_repo_setup \ | sudo bash -s -- --mariadb-maxscale-version=23.08 sudo apt install -y maxscale sudo systemctl enable maxscale -
Create the MaxScale user on the backend with the precise grants the monitor needs — broader grants are a security smell, narrower grants make
mariadbmonflap.CREATE USER 'maxscale'@'%' IDENTIFIED BY 'STRONG_PASS'; GRANT SELECT ON mysql.* TO 'maxscale'@'%'; GRANT SHOW DATABASES ON *.* TO 'maxscale'@'%'; GRANT REPLICATION CLIENT, REPLICATION SLAVE ADMIN, BINLOG ADMIN, RELOAD, PROCESS, SUPER, EVENT, SET USER ON *.* TO 'maxscale'@'%'; -
Write
/etc/maxscale.cnfwith one server section per backend, one monitor, one router service, and one listener.[maxscale] threads=auto admin_host=127.0.0.1 admin_secure_gui=true [db01] type=server address=10.0.0.11 port=3306 protocol=MariaDBBackend [db02] type=server address=10.0.0.12 port=3306 protocol=MariaDBBackend [Replication-Monitor] type=monitor module=mariadbmon servers=db01,db02 user=maxscale password=STRONG_PASS monitor_interval=2000ms auto_failover=true auto_rejoin=true enforce_read_only_slaves=true failover_timeout=10 [RW-Split-Service] type=service router=readwritesplit servers=db01,db02 user=maxscale password=STRONG_PASS master_failure_mode=fail_on_write master_reconnection=true transaction_replay=true transaction_replay_max_size=10Mi [RW-Listener] type=listener service=RW-Split-Service protocol=MariaDBClient port=4006 -
Start MaxScale and confirm the monitor has picked up the topology. A fresh start with healthy backends takes a few seconds before the roles stabilize.
sudo systemctl restart maxscale sudo journalctl -u maxscale -n 50 sudo maxctrl list servers -
Send a write and a read through the listener and confirm both succeed against the expected backends — write goes to the master, read can land on either.
mysql -h 127.0.0.1 -P 4006 -u app -p -e "CREATE TABLE test.routing_probe (id INT) ENGINE=InnoDB;" mysql -h 127.0.0.1 -P 4006 -u app -p -e "SELECT @@hostname FROM test.routing_probe LIMIT 0; SELECT @@hostname;" -
For Galera, swap the monitor module to
galeramonand the router config to recognize multiple writeable nodes —available_when_donor=falsekeeps SST donors out of the pool. Or constrain writes to one node viamaster_accept_reads=falsefor behaviour similar to active-passive.
Common pitfalls
- Pointing the application at
maxscale-host:3306— MaxScale’s listener port is whatever you set (4006here). Hitting 3306 talks to the backend directly and bypasses every protection MaxScale offers. - Leaving
auto_rejoin=false— after a failover, the demoted ex-primary stays inSlave/Stoppedforever; the cluster degrades silently until somebody runsmaxctrl call command mariadbmon rejoinmanually. - Missing
transaction_replay=true— when MaxScale fails over mid-transaction, the client sees a fatal error instead of a transparent retry. Replay covers most cases; it does not cover statements with non-deterministic output. enforce_read_only_slaves=falsein async topologies — application bugs that connect to a replica as a write user will succeed silently and create split-brain data; the slave will then fail to apply the next replicated write.- MaxScale admin interface bound to
0.0.0.0— the REST API uses the same credentials asmaxctrl; bind it to localhost or to the management network only.
MaxScale earns its place when a client cannot tolerate the application reconnecting after a primary failure — the routing layer absorbs the failover, the application sees one long-running connection. In the engagements we run, MaxScale’s monitor, services, and listener configuration are part of the database runbook: maxctrl is wired into our observability so the team sees a backend flap in seconds, failover policies are tested against drills not theory, and replication users are scoped to the grants they actually need. For the broader pattern of operating MariaDB at this layer, see /en/solutions/clustered-environments/.