Get started with MariaDB MaxScale, the advanced database proxy. These guides provide concise instructions for installation, configuration, and understanding core concepts for new deployments.
Start your journey with MariaDB MaxScale. This guide introduces the database proxy's architecture, key components, and basic setup steps for first-time users.
After MaxScale has been installed, test that MaxScale starts by executing sudo systemctl start maxscale, followed by sudo systemctl status maxscale.
Stop MaxScale with sudo systemctl stop maxscale. The log file is written at /var/log/maxscale/maxscale.log. If the startup failed, the log should explain why. With the default configuration file, MaxScale does not yet do anything interesting.
A functional configuration of MaxScale should include a listener, a service, a monitor and one or more servers. An incoming client connects to a listener port. Once the connection is established, the listener passes the client to a service. The service then handles all client traffic, from authentication to disconnection. Client queries are routed to servers and query results from servers back to the client. A monitor regularly checks the status of the servers.

MaxScale configuration files use the common file format. The files contain sections and each section can contain multiple key-value pairs. The MaxScale installer creates an example configuration file to /etc/maxscale.cnf.
Let's modify the example configuration file to include a service that routes all queries to one server. For this, you will need to have a running MariaDB Server accessible in the network. One option is to run a MariaDB Server . Once the server is running, log in to it with an administrative account and create a user account for MaxScale itself to use when monitoring the server and fetching user accounts. The following example creates user maxscale with all privileges.
Next, edit /etc/maxscale.cnf. Perform the following modifications:
In the section [server1], set correct address and port. These should match the running MariaDB Server.
In the section [MariaDB-Monitor], set user to maxscale and password to maxscale_passwd (or whatever user/password was created earlier).
The configuration file should now have the following effective contents.
Then, start MaxScale. If MaxScale started successfully, run maxctrl list servers in the terminal. If MaxScale can successfully connect to the server, the output should be approximately:
Next, check the log file at /var/log/maxscale/maxscale.log. It should have a message like:
If the monitor cannot connect to the server, the State is Down. In this case, check the log for error messages. Similarly, if the service cannot load user account information, an error is logged.
If everything is working properly, connect as client to the MaxScale listener port, configured to 4006.
Other user accounts on the server should work as well if their host patterns allow connections from MaxScale's IP address.
The Read-Write Service configured above only uses one server. To enable read-write splitting, a replication cluster with a primary server and one or more replicas is required. Setting up such a cluster is outside the scope of this document, see for more information.
Once the replicas are set up, add them to the MaxScale configuration file as separate sections: [server2], [server3] etc., similar to [server1]. Remember to set the addresses and ports. Then, add the server names to the servers-settings of the monitor:
Then, restart MaxScale to take the configuration into use and run maxctrl list servers once more. If replication is working and MaxScale can connect to all the servers, the output should be as below. If this is not the case, check the log again for error messages.
Run maxctrl show servers to get more detailed information about the servers such as connection and query counts, and maxctrl show monitors to see monitor-related information such as replication status.
Connect to the listener port again with mariadb -h127.0.0.1 -P4006 -umaxscale -pmaxscale_passwd and run the query select @@server_id; a few times. It should give the server id of a replica, alternating if multiple are available. This demonstrates that read queries are sent to the replicas. Writes and other queries that depend on the primary are sent to the primary only, e.g. select @@last_insert_id,@@server_id;. Reads inside transactions are also ran on the primary to maintain transaction consistency.
Filters are components added to the query processing chain that can act on the query. A typical use-case is logging. To add a log filter, add the following to the configuration file:
Then, add the filter to the service:
Again, restart MaxScale to take the configuration into use. MaxScale will now log any client queries passing through MaxScale to /var/log/maxscale/query_log.unified.
Add admin_secure_gui=false to the [maxscale]-section of the configuration file and restart MaxScale. This allows access to the GUI without configuring SSL certificates. Then, open a web browser and navigate to http://127.0.0.1:8989. A login screen should open, use username admin and password mariadb to access the GUI. The GUI can show MaxScale and server status, show and modify MaxScale configuration, perform SQL queries and much more. See for more information on the GUI.
The lists all global configuration parameters. The explains the ReadWriteSplit-router and its features, such as transaction replay and causal reads. The explains monitor features such as failover and switchover.
● maxscale.service - MariaDB MaxScale Database Proxy
Loaded: loaded (/usr/lib/systemd/system/maxscale.service; enabled; vendor preset: disabled)
Active: active (running) since Mon 2024-09-23 08:57:14 CEST; 6s ago[Read-Write-Service], set user to maxscale and password to maxscale_passwd (or whatever user/password was created earlier).CREATE USER 'maxscale' IDENTIFIED BY 'maxscale_passwd';
GRANT ALL PRIVILEGES ON *.* to 'maxscale';[maxscale]
threads=auto
[server1]
type=server
address=127.0.0.1
port=3306
[MariaDB-Monitor]
type=monitor
module=mariadbmon
servers=server1
user=maxscale
password=maxscale_passwd
monitor_interval=2s
[Read-Write-Listener]
type=listener
service=Read-Write-Service
port=4006
[Read-Write-Service]
type=service
router=readwritesplit
cluster=MariaDB-Monitor
user=maxscale
password=maxscale_passwd┌─────────┬───────────┬───────┬─────────────┬─────────────────┬─────────┬─────────────────┐
│ Server │ Address │ Port │ Connections │ State │ GTID │ Monitor │
├─────────┼───────────┼───────┼─────────────┼─────────────────┼─────────┼─────────────────┤
│ server1 │ 127.0.0.1 │ 3306 │ 0 │ Master, Running │ 1-100-3 │ MariaDB-Monitor │
└─────────┴───────────┴───────┴─────────────┴─────────────────┴─────────┴─────────────────┘2024-09-17 17:55:55 notice : Read 16 user@host entries from 'server1' for service 'Read-Write-Service'.mariadb -h127.0.0.1 -P4006 -umaxscale -pmaxscale_passwd
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 7
Server version: 11.4.3-MariaDB-log MariaDB Server
Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MariaDB [(none)]> select 1;
+---+
| 1 |
+---+
| 1 |
+---+
1 row in set (0,001 sec)[MariaDB-Monitor]
type=monitor
module=mariadbmon
servers=server1,server2,server3
user=maxscale
password=maxscale_passwd
monitor_interval=2s┌─────────┬───────────┬───────┬─────────────┬─────────────────┬─────────┬─────────────────┐
│ Server │ Address │ Port │ Connections │ State │ GTID │ Monitor │
├─────────┼───────────┼───────┼─────────────┼─────────────────┼─────────┼─────────────────┤
│ server1 │ 127.0.0.1 │ 3306 │ 0 │ Master, Running │ 1-100-3 │ MariaDB-Monitor │
├─────────┼───────────┼───────┼─────────────┼─────────────────┼─────────┼─────────────────┤
│ server2 │ 127.0.0.1 │ 3307 │ 0 │ Slave, Running │ 1-100-3 │ MariaDB-Monitor │
├─────────┼───────────┼───────┼─────────────┼─────────────────┼─────────┼─────────────────┤
│ server3 │ 127.0.0.1 │ 3308 │ 0 │ Slave, Running │ 1-100-3 │ MariaDB-Monitor │
└─────────┴───────────┴───────┴─────────────┴─────────────────┴─────────┴─────────────────┘[MyLogFilter]
type=filter
module=qlafilter
filebase=/var/log/maxscale/query_log
log_type=unified
flush=true[Read-Write-Service]
type=service
filters=MyLogFilter
router=readwritesplit
cluster=MariaDB-Monitor
user=maxscale
password=maxscale_passwdDiscover the capabilities of MariaDB MaxScale. This overview explains how the proxy manages high availability, load balancing, and security for your database infrastructure.
MariaDB MaxScale is an advanced, open-source database proxy, router, and load balancer designed to enhance the scalability, high availability, and security of your MariaDB deployments. It acts as an intelligent intermediary between your applications and your MariaDB servers, abstracting the underlying database topology.
MaxScale is not a database itself, but a sophisticated gateway that understands the MariaDB protocol. It intercepts client connections and routes them to the appropriate backend MariaDB servers based on configured rules, health checks, and workload types. This allows for flexible and dynamic management of database traffic without requiring changes to the application code.
MariaDB MaxScale provides several key functionalities that contribute to optimizing MariaDB environments:
Intelligent Routing and Load Balancing:
ReadWriteSplit Router: This is a primary feature that automatically distinguishes between read (SELECT) and write (INSERT, UPDATE, DELETE, DDL) statements. It intelligently routes all write statements to the designated primary server and distributes read statements across multiple replica servers, significantly improving read scalability and reducing the load on the primary.
Other Routers: MaxScale offers various routers for different use cases, such as routing to specific databases, connection-based routing, or custom routing logic.
By abstracting the database topology and intelligently managing connections, MariaDB MaxScale helps organizations achieve higher availability, better performance, and enhanced security for their MariaDB deployments.
High Availability and Automated Failover:
MaxScale constantly monitors the health of your MariaDB servers. In a replication setup (e.g., primary-replica or Galera Cluster), if the primary server fails, MaxScale can automatically detect the failure, promote a healthy replica to become the new primary, and seamlessly redirect client connections to the newly promoted server. This minimizes downtime and ensures continuous operation.
Seamless Server Maintenance:
MaxScale provides built-in mechanisms to place backend servers into maintenance mode without interrupting connected applications or clients. This allows administrators to perform tasks like patching, upgrades, or reconfigurations on individual servers while MaxScale intelligently redirects traffic away from them. Management can be done via the maxctrl command-line interface, MaxGUI (web interface), or REST API.
Security and Traffic Control:
MaxScale can implement granular security policies and traffic controls for database connections and queries. This includes features like firewalling, query filtering, and authentication proxying.
QLAfilter (Query Log Anonymizer Filter): This filter can be used to create an audit trail by logging all queries, with options to anonymize sensitive data, aiding in security audits and performance analysis.
Protocol Compatibility: MaxScale is designed to be compatible with standard MariaDB and MySQL client protocols, making it transparent to most applications.
Review known limitations and constraints of MariaDB MaxScale. Understand supported features, configuration boundaries, and protocol specifics to plan your deployment effectively.
While MariaDB MaxScale is a powerful tool for managing MariaDB deployments, it's essential to be aware of its limitations to ensure proper configuration and avoid unexpected behavior. This guide highlights key considerations when deploying and using MaxScale.
Limitation: Older versions of MaxScale (2.1.2 and earlier) had a strict line length limit of 1024 characters in the configuration file (maxscale.cnf).
Consideration: Ensure your MaxScale configuration lines do not exceed this limit for older versions. Modern versions (e.g., 2.3.0 and later) have significantly increased this limit (to 16,777,216 characters), making it less of a concern for current deployments. Always check the documentation for your specific MaxScale version.
Limitation: MaxScale operates under the assumption that certain MariaDB Server configuration parameters are set to their default values. A critical example is the assumption that autocommit is enabled for new connections.
Consideration: If your backend MariaDB servers deviate from default autocommit settings or other assumed defaults, it could lead to unexpected behavior in how MaxScale manages connections and routes queries, particularly with transaction handling. Always verify that your MariaDB server configurations align with MaxScale's expectations as outlined in its documentation.
Limitation: MaxScale uses a custom SQL parser to deduce transaction boundaries. This parser may not fully comprehend or correctly classify highly complex SQL statements or certain edge cases. This can lead to a mismatch between MaxScale's understanding of a connection's transaction state and the actual state on the backend database.
Specific Issue with XA Transactions: If a START TRANSACTION command fails internally on the backend due to an already open XA transaction (e.g., using XA START), MaxScale's parser might not correctly detect this failure. It could mistakenly assume a new transaction has started, leading to discrepancies in transaction state awareness, especially with the readwritesplit router.
Limitation: The ETL (Extract, Transform, Load) feature within MaxScale relies on the MariaDB Connector/ODBC driver for its functionality.
Consideration: To ensure stability and avoid potential crashes or memory leaks when using MaxScale's ETL capabilities, it is highly recommended to use MariaDB Connector/ODBC driver version 3.1.18 or later. Always ensure all components are compatible.
Query Classification: MaxScale's ability to route queries correctly relies on its query classification. If queries are ambiguous or use non-standard SQL, they might be misrouted.
Prepared Statements: While supported, complex interactions with prepared statements can sometimes expose nuances in parsing or routing.
Protocol Specifics: MaxScale aims for broad compatibility, but subtle differences in client or server protocol implementations might arise.
Understanding these limitations helps in designing a robust MaxScale deployment and troubleshooting potential issues effectively.
Configure secure access to your database. This guide explains how to set up authenticators in MaxScale to manage client credentials and validate connections to backend servers.
MariaDB MaxScale incorporates robust authentication modules to manage client access and ensure secure communication with your backend MariaDB servers. Understanding these modules is crucial for securing your database deployments when using MaxScale.
MaxScale's authentication modules (often referred to as "authenticator plugins") are components that handle client authentication. They determine how incoming clients verify their identity to MaxScale and, in turn, how MaxScale authenticates itself to the backend MariaDB servers. This process is similar to how authentication works directly with MariaDB Server using the MySQL protocol.
MaxScale employs a User Account Manager (UAM) for services that use a MariaDB protocol listener.
The UAM is responsible for storing and managing user account information.
It typically queries the mysql database on your backend MariaDB servers (usually the primary) to retrieve user account details.
Using this information, the UAM authenticates connecting clients, verifies their passwords, and checks their database access rights.
The user
MaxScale supports various authentication schemes through different plugins:
Standard MySQL Password: This is the most common authentication method, verifying user credentials against those stored in the backend MariaDB server's mysql.user table (or similar).
GSSAPI (Generic Security Service Application Programming Interface): Provides secure authentication methods, often used in enterprise environments with Kerberos or similar systems.
PAM (Pluggable Authentication Modules): Allows MaxScale to integrate with PAM, enabling authentication against external systems like Unix system users, LDAP, or Active Directory.
Authentication options are primarily defined within the listener configuration of your MaxScale service in the maxscale.cnf file.
a. Specifying the Authenticator:
The authenticator parameter specifies which authentication plugin to use for a particular listener.
Example maxscale.cnf snippet (simplified):
Ini, TOML
b. Authenticator Options (authenticator_options):
Additional settings can be passed to the authenticator plugin using authenticator_options. These are comma-separated key-value pairs.
Common authenticator_options:
skip_authentication=true: (Use with extreme caution, typically only for development/testing). This option bypasses password checks for connecting clients. Clients will still need a valid username in the backend database, but their password will not be verified.
match_host=false: Disables host matching for user accounts. By default, MariaDB (and thus MaxScale's UAM) matches user accounts based on both username and host (e.g., 'user'@'localhost'). Setting this to false means only the username needs to match.
Example with options:
Ini, TOML
By configuring these authentication modules, you can control how clients connect to your MariaDB through MaxScale, enforce security policies, and integrate with existing authentication infrastructure.
passwordlower_case_table_names=true/false: Controls how database names are matched during authentication, similar to the lower_case_table_names system variable in MariaDB Server.
[my_service]
type=service
router=readwritesplit
servers=server1,server2
user=maxscale_user # User MaxScale uses to connect to backend MariaDB for UAM
password=maxscale_password
[my_listener]
type=listener
service=my_service
protocol=MariaDBClient
port=3306
authenticator=MariaDBAuth # Example: Use the standard MariaDB password authentication
# authenticator=GSSAPIAuth # Or GSSAPI authentication
# authenticator=PAMAuth # Or PAM authentication[my_listener]
# ... other settings ...
authenticator=MariaDBAuth
authenticator_options=skip_authentication=true,match_host=falseFollow step-by-step instructions to install MariaDB MaxScale on major Linux distributions. This guide covers repository configuration and package installation.
MariaDB MaxScale is an advanced, open-source database proxy that provides intelligent routing, load balancing, high availability, and security features for your MariaDB and MySQL deployments. It acts as an intermediary, forwarding database statements to one or more backend database servers based on configured rules and server roles, all transparently to your applications.
Key concepts
To understand MaxScale, familiarize yourself with these core components:
Servers: These are your backend MariaDB or MySQL instances that MaxScale will manage traffic to.
Monitors: Plugins that observe the health and state of your backend servers (e.g., primary, replica, down).
Routers: Plugins that determine how client queries are directed to backend servers (e.g., readwritesplit router for directing writes to a primary and reads to replicas).
Installation
MariaDB MaxScale is typically installed from the official MariaDB repositories.
Add MariaDB Repository:
Use the MariaDB Repository Configuration Tool (search "MariaDB Repository Generator") to get specific instructions for your OS and MaxScale version.
Installation for Debian/Ubuntu:
Installation for RHEL/Rocky Linux/Alma Linux:
Basic configuration
MaxScale's configuration is primarily done in its main configuration file in /etc/maxscale.cnf.
Define Servers:
Add a section for each of your backend MariaDB servers.
Define a Monitor:
This section tells MaxScale how to monitor your backend servers' health and roles and groups them into a cluster of servers.
Important: Create the maxscale_monitor user on your backend MariaDB servers with appropriate privileges:
Complete configuration
Your /etc/maxscale.cnf should now look like this:
Start and enable MaxScale
After configuring maxscale.cnf, start and enable the MaxScale service.
Basic usage and verification
Once MaxScale is running, configure your applications to connect to MaxScale's listener port instead of directly to a MariaDB server.
Example (Connect with mariadb client from the MaxScale server):
Verify Read-Write Split (if configured):
Connect to MaxScale (127.0.0.1:3306).
Listeners: Define how clients connect to MaxScale (port, protocol) and which service they connect to.
Filters: Optional components that can inspect, modify, or log queries as they pass through MaxScale (e.g., qlafilter for auditing).
This configures how MaxScale routes queries. The readwritesplit router is very common for replication setups as it load balances read while routing writes to the primary node.
Important: Create the maxscale_user on your backend MariaDB servers with the following privileges:
Define a Listener:
This specifies the port and protocol MaxScale will listen on for incoming client connections and which service to direct them to.
Global MaxScale Configuration (usually at the top of maxscale.cnf):
Execute a WRITE query (e.g., INSERT INTO your_table ...). This should be routed to the primary server.
Execute a READ query (e.g., SELECT * FROM your_table). This should be load-balanced across your replica servers.
You can use maxctrl list servers and maxctrl show servers to observe routing in action.
sudo apt update
sudo apt install -y curl
curl -LsS https://r.mariadb.com/downloads/mariadb_repo_setup | sudo bash
sudo apt install -y maxscalecurl -LsS https://r.mariadb.com/downloads/mariadb_repo_setup | sudo bash
sudo dnf install -y maxscale[server1]
type=server
# IP address or hostname of your first MariaDB server
address=192.168.1.101
[server2]
type=server
# IP address or hostname of your second MariaDB server
address=192.168.1.102
# Set the port if MariaDB is listening on a non-default port
port=3307[MariaDB-Cluster]
type=monitor
# The MariaDB asynchronous replication monitoring module
module=mariadbmon
# List of servers to monitor
servers=server1,server2
# The user used for monitoring
user=maxscale_monitor
password=monitor_password
# Check every 5 seconds
monitor_interval=5sCREATE USER 'maxscale_monitor'@'%' IDENTIFIED BY 'monitor_password';
GRANT BINLOG ADMIN, BINLOG MONITOR, CONNECTION ADMIN, READ_ONLY ADMIN, REPLICATION SLAVE ADMIN, SLAVE MONITOR, RELOAD, PROCESS, SUPER, EVENT, SET USER, SHOW DATABASES ON *.* TO `maxscale_monitor`@`%`;
GRANT SELECT ON mysql.global_priv TO 'maxscale_monitor'@'%';[maxscale]
threads=auto
[server1]
type=server
address=192.168.1.101
[server2]
type=server
address=192.168.1.102
port=3307
[MariaDB-Cluster]
type=monitor
module=mariadbmon
servers=server1,server2
user=maxscale_monitor
password=monitor_password
monitor_interval=5s
[Read-Write-Service]
type=service
router=readwritesplit
cluster=MariaDB-Cluster
user=maxscale_user
password=maxscale_password
[Read-Write-Listener]
type=listener
service=Read-Write-Service
port=3306sudo systemctl start maxscale
sudo systemctl enable maxscale
sudo systemctl status maxscale # Check statusmariadb -h 127.0.0.1 -P 3306 -u my-user -p[Read-Write-Service]
type=service
# The readwritesplit router module load balances reads and routes writes to the primary node
router=readwritesplit
# Servers available for this service
cluster=MariaDB-Cluster
# The user account used to fetch the user information from MariaDB
user=maxscale_user
password=maxscale_passwordCREATE USER 'maxscale_user'@'%' IDENTIFIED BY 'maxscale_password';
GRANT SELECT ON mysql.user TO 'maxscale_user'@'%';
GRANT SELECT ON mysql.db TO 'maxscale_user'@'%';
GRANT SELECT ON mysql.tables_priv TO 'maxscale_user'@'%';
GRANT SELECT ON mysql.columns_priv TO 'maxscale_user'@'%';
GRANT SELECT ON mysql.procs_priv TO 'maxscale_user'@'%';
GRANT SELECT ON mysql.proxies_priv TO 'maxscale_user'@'%';
GRANT SELECT ON mysql.roles_mapping TO 'maxscale_user'@'%';
GRANT SHOW DATABASES ON *.* TO 'maxscale_user'@'%';[Read-Write-Listener]
type=listener
# The service that this listener connects to
service=Read-Write-Service
# The port that MaxScale will listen on for client applications
port=3306[maxscale]
# Select the number of worker threads automatically based on the CPU thread count
threads=auto