Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
[CDC-Service]
type=service
router=avrorouter
user=maxuser
password=maxpwdfoobar:SHA1(foopasswd) -> 666f6f6261723a3137336363643535253331REGISTER UUID=11ec2300-2e23-11e6-8308-0002a5d5c51b, TYPE=AVROREQUEST-DATA db1.table1
REQUEST-DATA dbi1.table1.000003
REQUEST-DATA db2.table4 0-11-345GET /v1/monitors/:name{
"data": {
"attributes": {
"module": "mariadbmon",
"monitor_diagnostics": {
"master": "server1",
"master_gtid_domain_id": 0,
"primary": null,
"server_info": [
{
"gtid_binlog_pos": "0-3000-5",
"gtid_current_pos": "0-3000-5",
"lock_held": null,
"master_group": null,
"name": "server1",
"read_only": false,
"server_id": 3000,
"slave_connections": [],
"state_details": null
},
{
"gtid_binlog_pos": "0-3000-5",
"gtid_current_pos": "0-3000-5",
"lock_held": null,
"master_group": null,
"name": "server2",
"read_only": false,
"server_id": 3001,
"slave_connections": [
{
"connection_name": "",
"gtid_io_pos": "",
"last_io_error": "",
"last_sql_error": "",
"master_host": "127.0.0.1",
"master_port": 3000,
"master_server_id": 3000,
"master_server_name": "server1",
"seconds_behind_master": 0,
"slave_io_running": "Yes",
"slave_sql_running": "Yes",
"using_gtid": "No"
}
],
"state_details": null
}
],
"state": "Idle"
},
"parameters": {
"assume_unique_hostnames": true,
"auto_failover": false,
"auto_rejoin": false,
"backend_connect_attempts": 1,
"backend_connect_timeout": "3000ms",
"backend_read_timeout": "3000ms",
"backend_write_timeout": "3000ms",
"backup_storage_address": null,
"backup_storage_path": null,
"cooperative_monitoring_locks": "none",
"cs_admin_api_key": null,
"cs_admin_base_path": "/cmapi/0.4.0",
"cs_admin_port": 8640,
"demotion_sql_file": null,
"disk_space_check_interval": "0ms",
"disk_space_threshold": null,
"enforce_read_only_slaves": false,
"enforce_simple_topology": false,
"enforce_writable_master": false,
"events": "all,master_down,master_up,slave_down,slave_up,server_down,server_up,synced_down,synced_up,donor_down,donor_up,lost_master,lost_slave,lost_synced,lost_donor,new_master,new_slave,new_synced,new_donor",
"failcount": 5,
"failover_timeout": "90000ms",
"handle_events": true,
"journal_max_age": "28800000ms",
"maintenance_on_low_disk_space": true,
"mariadb-backup_parallel": 1,
"mariadb-backup_use_memory": "1G",
"master_conditions": "primary_monitor_master",
"master_failure_timeout": "10000ms",
"module": "mariadbmon",
"monitor_interval": "1000ms",
"password": "*****",
"promotion_sql_file": null,
"rebuild_port": 4444,
"replication_custom_options": null,
"replication_master_ssl": false,
"replication_password": "*****",
"replication_user": "maxuser",
"script": null,
"script_max_replication_lag": -1,
"script_timeout": "90000ms",
"servers_no_promotion": null,
"slave_conditions": "",
"ssh_check_host_key": true,
"ssh_keyfile": null,
"ssh_port": 22,
"ssh_timeout": "10000ms",
"ssh_user": null,
"switchover_on_low_disk_space": false,
"switchover_timeout": "90000ms",
"type": "monitor",
"user": "maxuser",
"verify_master_failure": true
},
"source": {
"file": "/etc/maxscale.cnf",
"type": "static"
},
"state": "Running",
"ticks": 12
},
"id": "MariaDB-Monitor",
"links": {
"self": "http://localhost:8989/v1/monitors/MariaDB-Monitor/"
},
"relationships": {
"servers": {
"data": [
{
"id": "server1",
"type": "servers"
},
{
"id": "server2",
"type": "servers"
}
],
"links": {
"related": "http://localhost:8989/v1/servers/",
"self": "http://localhost:8989/v1/monitors/MariaDB-Monitor/relationships/servers/"
}
},
"services": {
"data": [
{
"id": "RW-Split-Router",
"type": "services"
}
],
"links": {
"related": "http://localhost:8989/v1/services/",
"self": "http://localhost:8989/v1/monitors/MariaDB-Monitor/relationships/services/"
}
}
},
"type": "monitors"
},
"links": {
"self": "http://localhost:8989/v1/monitors/MariaDB-Monitor/"
}
}GET /v1/monitors{
"data": [
{
"attributes": {
"module": "mariadbmon",
"monitor_diagnostics": {
"master": "server1",
"master_gtid_domain_id": 0,
"primary": null,
"server_info": [
{
"gtid_binlog_pos": "0-3000-5",
"gtid_current_pos": "0-3000-5",
"lock_held": null,
"master_group": null,
"name": "server1",
"read_only": false,
"server_id": 3000,
"slave_connections": [],
"state_details": null
},
{
"gtid_binlog_pos": "0-3000-5",
"gtid_current_pos": "0-3000-5",
"lock_held": null,
"master_group": null,
"name": "server2",
"read_only": false,
"server_id": 3001,
"slave_connections": [
{
"connection_name": "",
"gtid_io_pos": "",
"last_io_error": "",
"last_sql_error": "",
"master_host": "127.0.0.1",
"master_port": 3000,
"master_server_id": 3000,
"master_server_name": "server1",
"seconds_behind_master": 0,
"slave_io_running": "Yes",
"slave_sql_running": "Yes",
"using_gtid": "No"
}
],
"state_details": null
}
],
"state": "Idle"
},
"parameters": {
"assume_unique_hostnames": true,
"auto_failover": false,
"auto_rejoin": false,
"backend_connect_attempts": 1,
"backend_connect_timeout": "3000ms",
"backend_read_timeout": "3000ms",
"backend_write_timeout": "3000ms",
"backup_storage_address": null,
"backup_storage_path": null,
"cooperative_monitoring_locks": "none",
"cs_admin_api_key": null,
"cs_admin_base_path": "/cmapi/0.4.0",
"cs_admin_port": 8640,
"demotion_sql_file": null,
"disk_space_check_interval": "0ms",
"disk_space_threshold": null,
"enforce_read_only_slaves": false,
"enforce_simple_topology": false,
"enforce_writable_master": false,
"events": "all,master_down,master_up,slave_down,slave_up,server_down,server_up,synced_down,synced_up,donor_down,donor_up,lost_master,lost_slave,lost_synced,lost_donor,new_master,new_slave,new_synced,new_donor",
"failcount": 5,
"failover_timeout": "90000ms",
"handle_events": true,
"journal_max_age": "28800000ms",
"maintenance_on_low_disk_space": true,
"mariadb-backup_parallel": 1,
"mariadb-backup_use_memory": "1G",
"master_conditions": "primary_monitor_master",
"master_failure_timeout": "10000ms",
"module": "mariadbmon",
"monitor_interval": "1000ms",
"password": "*****",
"promotion_sql_file": null,
"rebuild_port": 4444,
"replication_custom_options": null,
"replication_master_ssl": false,
"replication_password": "*****",
"replication_user": "maxuser",
"script": null,
"script_max_replication_lag": -1,
"script_timeout": "90000ms",
"servers_no_promotion": null,
"slave_conditions": "",
"ssh_check_host_key": true,
"ssh_keyfile": null,
"ssh_port": 22,
"ssh_timeout": "10000ms",
"ssh_user": null,
"switchover_on_low_disk_space": false,
"switchover_timeout": "90000ms",
"type": "monitor",
"user": "maxuser",
"verify_master_failure": true
},
"source": {
"file": "/etc/maxscale.cnf",
"type": "static"
},
"state": "Running",
"ticks": 12
},
"id": "MariaDB-Monitor",
"links": {
"self": "http://localhost:8989/v1/monitors/MariaDB-Monitor/"
},
"relationships": {
"servers": {
"data": [
{
"id": "server1",
"type": "servers"
},
{
"id": "server2",
"type": "servers"
}
],
"links": {
"related": "http://localhost:8989/v1/servers/",
"self": "http://localhost:8989/v1/monitors/MariaDB-Monitor/relationships/servers/"
}
},
"services": {
"data": [
{
"id": "RW-Split-Router",
"type": "services"
}
],
"links": {
"related": "http://localhost:8989/v1/services/",
"self": "http://localhost:8989/v1/monitors/MariaDB-Monitor/relationships/services/"
}
}
},
"type": "monitors"
}
],
"links": {
"self": "http://localhost:8989/v1/monitors/"
}
}POST /v1/monitors{
data: {
"id": "test-monitor", // Name of the monitor
"type": "monitors",
"attributes": {
"module": "mariadbmon", // The monitor uses the mariadbmon module
"parameters": { // Monitor parameters
"monitor_interval": 1000,
"user": "maxuser,
"password": "maxpwd"
}
},
"relationships": { // List of server relationships that this monitor uses
"servers": {
"data": [ // This monitor uses two servers
{
"id": "server1",
"type": "servers"
},
{
"id": "server2",
"type": "servers"
}
]
}
}
}
}PATCH /v1/monitors/:namePATCH /v1/monitors/:name/relationships/serversPATCH /v1/monitors/my-monitor/relationships/servers
{
data: [
{ "id": "my-server", "type": "servers" }
]
}PATCH /v1/monitors/my-monitor/relationships/servers
{
data: []
}DELETE /v1/monitors/:namePUT /v1/monitors/:name/stopPUT /v1/monitors/:name/startThis release of MariaDB MaxScale introduces powerful new features. It includes Workload Capture and Replay for production traffic analysis and a Diff Router for comparing server behavior.
This is your starting point for MariaDB MaxScale 25.01. Find essential guides for installation, learn how to configure MaxScale for your needs, and explore tutorials to get up and running.
Protocol modules in MariaDB MaxScale interpret client-server communication. This section covers the available protocols, including the MariaDB, NoSQL, and Change Data Capture (CDC) modules.
moduleuserpasswordserversmonitor_intervalbackend_connect_timeoutbackend_write_timeoutbackend_read_timeoutbackend_connect_attemptsdisk_space_thresholddisk_space_check_intervalscriptscript_timeouteventsjournal_max_ageassume_unique_hostnamesprivate_addressmaster_conditionsslave_conditionsfailcountenforce_writable_masterenforce_read_only_slavesenforce_read_only_serversmaintenance_on_low_disk_spacecooperative_monitoring_locksscript_max_replication_lagfetch-cmd-resultcancel-cmdManage MariaDB MaxScale programmatically using the REST API. This interface allows for the dynamic administration and monitoring of MaxScale resources like servers, services, and listeners.
Secure your MariaDB MaxScale deployment with authenticators. These modules manage client authentication with backend servers, supporting diverse mechanisms for enhanced security.
master_upslave_downslave_upserver_downserver_uplost_masterlost_slavenew_masternew_slaveservers=MyServer1,MyServer2monitor_interval=2sbackend_connect_timeout=3sbackend_write_timeout=3sbackend_read_timeout=3sbackend_connect_attempts=1[server1]
type=server
...
[server2]
type=server
...
[server3]
type=server
...
[monitor]
type=monitor
servers=server1,server2,server3
disk_space_threshold=/data:80
...[server1]
type=server
disk_space_threshold=/data:80
...
[server2]
type=server
disk_space_threshold=/Data:80
...
[server3]
type=server
disk_space_threshold=/DBData:80
...
[monitor]
type=monitor
servers=server1,server2,server3
...[server1]
type=server
disk_space_threshold=/DbData:80
...
[server2]
type=server
...
[server3]
type=server
...
[monitor]
type=monitor
servers=server1,server2,server3
disk_space_threshold=/data:80
...script=/home/user/myscript.sh initiator=$INITIATOR event=$EVENT live_nodes=$NODELIST/home/user/myscript.sh initiator=[192.168.0.10]:3306 event=master_down live_nodes=[192.168.0.201]:3306,[192.168.0.121]:3306events=master_down,slave_down[MyMonitor]
type=monitor
module=mariadbmon
servers=C1N1,C1N2,C1N3
user=maxscale
password=password
monitor_interval=10s
script=/path/to/maxscale_monitor_alert_script.sh --initiator=$INITIATOR --parent=$PARENT --children=$CHILDREN --event=$EVENT --node_list=$NODELIST --list=$LIST --master_list=$MASTERLIST --slave_list=$SLAVELIST --synced_list=$SYNCEDLISTconnecting_slaveconnected_slaverunning_slaveprimary_monitor_masterdisk_space_oklinked_masterrunning_masterwritable_masterprimary_monitor_mastermajority_of_allmajority_of_runningonyes1falseoffno0safeCREATE USER 'maxscale'@'maxscalehost' IDENTIFIED BY 'maxscale-password';
GRANT REPLICATION CLIENT ON *.* TO 'maxscale'@'maxscalehost';GRANT REPLICATION SLAVE ADMIN ON *.* TO 'maxscale'@'maxscalehost';GRANT REPLICA MONITOR ON *.* TO 'maxscale'@'maxscalehost';GRANT FILE ON *.* TO 'maxscale'@'maxscalehost';GRANT CONNECTION ADMIN ON *.* TO 'maxscale'@'maxscalehost';GRANT SUPER, RELOAD, PROCESS, SHOW DATABASES, EVENT ON *.* TO 'maxscale'@'maxscalehost';
GRANT SELECT ON mysql.user TO 'maxscale'@'maxscalehost';GRANT SELECT ON mysql.global_priv TO 'maxscale'@'maxscalehost';GRANT RELOAD, PROCESS, SHOW DATABASES, EVENT, SET USER, READ_ONLY ADMIN ON *.* TO 'maxscale'@'maxscalehost';
GRANT REPLICATION SLAVE ADMIN, BINLOG ADMIN, CONNECTION ADMIN ON *.* TO 'maxscale'@'maxscalehost';
GRANT SELECT ON mysql.user TO 'maxscale'@'maxscalehost';
GRANT SELECT ON mysql.global_priv TO 'maxscale'@'maxscalehost';CREATE USER 'replication'@'replicationhost' IDENTIFIED BY 'replication-password';
GRANT REPLICATION SLAVE ON *.* TO 'replication'@'replicationhost';[MyMonitor]
type=monitor
module=mariadbmon
servers=server1,server2,server3
user=myuser
password=mypwdmaster_conditions=connected_slave,running_slaveslave_conditions=running_master,writable_master(monitor_interval + backend_connect_timeout) * failcountmaxctrl clear server server2 Maintcall command mariadbmon failover MONITORcall command mariadbmon failover-safe MONITORcall command mariadbmon switchover MONITOR [NEW_PRIMARY] [OLD_PRIMARY]call command mariadbmon switchover-force MONITOR [NEW_PRIMARY] [OLD_PRIMARY]call command mariadbmon rejoin MONITOR OLD_PRIMARYmaxctrl call command mariadbmon reset-replication MONITOR [NEW_PRIMARY]maxctrl call command mariadbmon failover MyMonitor
maxctrl call command mariadbmon failover-safe MyMonitor
maxctrl call command mariadbmon rejoin MyMonitor OldPrimaryServ
maxctrl call command mariadbmon reset-replication MyMonitor
maxctrl call command mariadbmon reset-replication MyMonitor NewPrimaryServ
maxctrl call command mariadbmon switchover MyMonitor
maxctrl call command mariadbmon switchover MyMonitor NewPrimaryServ
maxctrl call command mariadbmon switchover MyMonitor NewPrimaryServ OldPrimaryServ
maxctrl call command mariadbmon switchover-force MyMonitor NewPrimaryServ/v1/maxscale/modules/mariadbmon/<operation>?<monitor-name>&<server-name1>&<server-name2>[Cluster1]
type=monitor
module=mariadbmon
servers=server1, server2, server3, server 4
.../v1/maxscale/modules/mariadbmon/switchover?Cluster1&server4&server2/v1/maxscale/modules/mariadbmon/failover?Cluster1
/v1/maxscale/modules/mariadbmon/rejoin?Cluster1&server3
/v1/maxscale/modules/mariadbmon/reset-replication?Cluster1&server3maxctrl call command mariadbmon async-switchover Cluster1
OK
maxctrl call command mariadbmon fetch-cmd-result Cluster1
{
"links": {
"self": "http://localhost:8989/v1/maxscale/modules/mariadbmon/fetch-cmd-result"
},
"meta": "switchover completed successfully."
}maxctrl call command mariadbmon switchover monitor=MyMonitor new_primary=MyServer2 async=1 force=1maxctrl call command mariadbmon switchover monitor=MyMonitor old_primary_maint=1switchover_on_low_disk_space=trueenforce_simple_topology=truereplication_custom_options=MASTER_SSL_CERT = '/tmp/certs/client-cert.pem',
MASTER_SSL_KEY = '/tmp/certs/client-key.pem',
MASTER_SSL_CA = '/tmp/certs/ca.pem',
MASTER_SSL_VERIFY_SERVER_CERT=0servers_no_promotion=backup_dc_server1,backup_dc_server2promotion_sql_file=/home/root/scripts/promotion.sql
demotion_sql_file=/home/root/scripts/demotion.sqlmaxctrl call command mariadbmon release-locks MyMonitor1write_test_interval=20sCREATE OR REPLACE TABLE mxs.maxscale_write_test
(id INT UNSIGNED AUTO_INCREMENT PRIMARY KEY NOT NULL,
`date` TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
`gtid` TEXT NULL);GRANT SELECT, INSERT, DELETE, CREATE, DROP ON `mxs`.* TO 'maxscale'@'maxscalehost';write_test_table=mxs.my_write_test_tablemaxctrl call command mariadbmon async-rebuild-server MyMonitor MyTargetServer MySourceServermaxctrl call command mariadbmon async-rebuild-server MyMonitor MyTargetServer MySourceServer /my_datadirmaxctrl call command mariadbmon async-create-backup MyMonitor MySourceServer wednesday_161122maxctrl call command mariadbmon async-restore-from-backup MyMonitor MyTargetServer wednesday_161122maxctrl call command mariadbmon async-restore-from-backup MyMonitor MyTargetServer wednesday_161122 /my_datadirmariadb-backup_use_memory=2Gmariadb-backup_parallel=2backup_storage_address=192.168.1.11backup_storage_path=/home/maxscale_ssh_user/backup_storagejohnny ALL= NOPASSWD: /bin/systemctl stop mariadb
johnny ALL= NOPASSWD: /bin/systemctl start mariadb
johnny ALL= NOPASSWD: /usr/sbin/lsof
johnny ALL= NOPASSWD: /bin/kill
johnny ALL= NOPASSWD: /usr/bin/mariadb-backup
johnny ALL= NOPASSWD: /bin/mbstream
johnny ALL= NOPASSWD: /bin/rm -rf /var/lib/mysql/*
johnny ALL= NOPASSWD: /bin/chown -R mysql\:mysql /var/lib/mysql
johnny ALL= NOPASSWD: /bin/cat /var/lib/mysql/xtrabackup_binlog_info
johnny ALL= NOPASSWD: /bin/tar -xz -C /var/lib/mysql/maxctrl call command mariadbmon cs-get-status <monitor-name>
maxctrl call command mariadbmon async-cs-get-status <monitor-name>maxctrl call command mariadbmon cs-get-status MyMonitor
{
"mcs1": {
"cluster_mode": "readwrite",
"dbrm_mode": "master",
<snip>
maxctrl call command mariadbmon async-cs-get-status MyMonitor
OK
maxctrl call command mariadbmon fetch-cmd-result MyMonitor
{
"mcs1": {
"cluster_mode": "readwrite",
"dbrm_mode": "master",
<snip>maxctrl call command mariadbmon async-cs-add-node <monitor-name> <node-host> <timeout>
maxctrl call command mariadbmon async-cs-remove-node <monitor-name> <node-host> <timeout>maxctrl call command mariadbmon async-cs-add-node MyMonitor mcs3 1m
OK
maxctrl call command mariadbmon fetch-cmd-result MyMonitor
{
"node_id": "mcs3",
"timestamp": "2022-05-05 08:07:51.518268"
}
maxctrl call command mariadbmon async-cs-remove-node MyMonitor mcs3 1m
OK
maxctrl call command mariadbmon fetch-cmd-result MyMonitor
{
"node_id": "mcs3",
"timestamp": "2022-05-05 10:46:46.506947"
}maxctrl call command mariadbmon async-cs-start-cluster <monitor-name> <timeout>
maxctrl call command mariadbmon async-cs-stop-cluster <monitor-name> <timeout>maxctrl call command mariadbmon async-cs-start-cluster MyMonitor 1m
OK
maxctrl call command mariadbmon fetch-cmd-result MyMonitor
{
"timestamp": "2022-05-05 09:41:57.140732"
}
maxctrl call command mariadbmon async-cs-stop-cluster MyMonitor 1m
OK
maxctrl call command mariadbmon fetch-cmd-result MyMonitor
{
"mcs1": {
"timestamp": "2022-05-05 09:45:33.779837"
},
<snip>maxctrl call command mariadbmon async-cs-set-readonly <monitor-name> <timeout>
maxctrl call command mariadbmon async-cs-set-readwrite <monitor-name> <timeout>maxctrl call command mariadbmon async-cs-set-readonly MyMonitor 30s
OK
maxctrl call command mariadbmon fetch-cmd-result MyMonitor
{
"cluster-mode": "readonly",
"timestamp": "2022-05-05 09:49:18.365444"
}
maxctrl call command mariadbmon async-cs-set-readwrite MyMonitor 30s
OK
maxctrl call command mariadbmon fetch-cmd-result MyMonitor
{
"cluster-mode": "readwrite",
"timestamp": "2022-05-05 09:50:30.718972"
}cs_admin_port=8641cs_admin_api_key=somekey123maxctrl call command mariadbmon fetch-cmd-result MariaDB-Monitor
"switchover completed successfully."maxctrl call command mariadbmon cancel-cmd MariaDB-Monitor
OK

CREATE USER 'maxscale'@'%' IDENTIFIED BY 'maxscale_pw';
GRANT SELECT ON mysql.user TO 'maxscale'@'%';
GRANT SELECT ON mysql.db TO 'maxscale'@'%';
GRANT SELECT ON mysql.tables_priv TO 'maxscale'@'%';
GRANT SELECT ON mysql.columns_priv TO 'maxscale'@'%';
GRANT SELECT ON mysql.procs_priv TO 'maxscale'@'%';
GRANT SELECT ON mysql.proxies_priv TO 'maxscale'@'%';
GRANT SELECT ON mysql.roles_mapping TO 'maxscale'@'%';
GRANT SHOW DATABASES ON *.* TO 'maxscale'@'%';CREATE USER 'jdoe'@'maxscale-host' IDENTIFIED BY 'my_secret_password';MariaDB [(none)]> SHOW GRANTS FOR 'jdoe'@'client-host';
+-----------------------------------------------------------------------+
| Grants for jdoe@client-host |
+-----------------------------------------------------------------------+
| GRANT SELECT, INSERT, UPDATE, DELETE ON *.* TO 'jdoe'@'client-host' |
+-----------------------------------------------------------------------+
1 row in set (0.01 sec)GRANT SELECT, INSERT, UPDATE, DELETE ON *.* TO 'jdoe'@'maxscale-host';[maxscale]
threads=autosudo systemctl start maxscalesudo service maxscale start% sudo maxctrl list services
┌──────────────────┬────────────────┬─────────────┬───────────────────┬───────────────────────────┐
│ Service │ Router │ Connections │ Total Connections │ Servers │
├──────────────────┼────────────────┼─────────────┼───────────────────┼───────────────────────────┤
│ Splitter-Service │ readwritesplit │ 1 │ 1 │ dbserv1, dbserv2, dbserv3 │
└──────────────────┴────────────────┴─────────────┴───────────────────┴───────────────────────────┘
% sudo maxctrl list servers
┌─────────┬─────────────┬──────┬─────────────┬─────────────────┬───────────┐
│ Server │ Address │ Port │ Connections │ State │ GTID │
├─────────┼─────────────┼──────┼─────────────┼─────────────────┼───────────┤
│ dbserv1 │ 192.168.2.1 │ 3306 │ 0 │ Master, Running │ 0-3000-62 │
├─────────┼─────────────┼──────┼─────────────┼─────────────────┼───────────┤
│ dbserv2 │ 192.168.2.2 │ 3306 │ 0 │ Slave, Running │ 0-3000-62 │
├─────────┼─────────────┼──────┼─────────────┼─────────────────┼───────────┤
│ dbserv3 │ 192.168.2.3 │ 3306 │ 0 │ Slave, Running │ 0-3000-62 │
└─────────┴─────────────┴──────┴─────────────┴─────────────────┴───────────┘
% sudo maxctrl list listeners Splitter-Service
┌───────────────────┬──────┬──────┬─────────┐
│ Name │ Port │ Host │ State │
├───────────────────┼──────┼──────┼─────────┤
│ Splitter-Listener │ 3306 │ │ Running │
└───────────────────┴──────┴──────┴─────────┘Explore the connectors available for MariaDB MaxScale 25.01. This section details the MaxScale CDC Connector, a C++ API allowing applications to consume a stream of database change events.
Filters in MariaDB MaxScale intercept and modify database traffic. Use them to transform, block, or log queries, enabling fine-grained control over your database workload and security.
Monitors are essential for high availability, tracking the status of backend servers. They detect failures, promote replicas, and enable automatic failover, ensuring service continuity.
Get hands-on experience with MariaDB MaxScale 25.01. These tutorials provide step-by-step instructions for common tasks like setting up read-write splitting, failover, and sharding.
Routers are the core of MariaDB MaxScale services, intelligently managing database traffic. This section details available routers, from read-write splitting to sharding and replication.
[avro-service]
type=service
router=avrorouter
source=replication-service
user=cdc_user
password=cdc_password[MyListener]
type=listener
authenticator=mariadbauth
authenticator_options=clear_pw_passthrough=true
ssl=true
<other options>[MyListener]
type=listener
service=MyService
protocol=mariadbprotocol
mariadbprotocol.allow_replication=false
port=3306#include <maxscale/modulecmd.hh>
bool my_simple_cmd(const MODULECMD_ARG *argv)
{
printf("%d arguments given\n", argv->argc);
}
int main(int argc, char **argv)
{
modulecmd_arg_type_t my_args[] =
{
{MODULECMD_ARG_BOOLEAN, "This is a boolean parameter"},
{MODULECMD_ARG_STRING | MODULECMD_ARG_OPTIONAL, "This is an optional string parameter"}
};
// Register the command
modulecmd_register_command("my_module", "my_command", my_simple_cmd, 2, my_args);
// Find the registered command
const MODULECMD *cmd = modulecmd_find_command("my_module", "my_command");
// Parse the arguments for the command
const void *arglist[] = {"true", "optional string"};
MODULECMD_ARG *arg = modulecmd_arg_parse(cmd, arglist, 2);
// Call the module command
modulecmd_call_command(cmd, arg);
// Free the parsed arguments
modulecmd_arg_free(arg);
return 0;
}[MyComment]
type=filter
module=comment
inject="Comment to be injected"
[MyService]
type=service
router=readwritesplit
servers=server1
user=myuser
password=mypasswd
filters=MyComment[IPComment]
type=filter
module=comment
inject="IP=$IP"
[MyService]
type=service
router=readwritesplit
servers=server1
user=myuser
password=mypasswd
filters=IPCommentSELECT user FROM people;/* IP=::ffff:127.0.0.1 */SELECT user FROM people;maxctrl call command cdc add_user <service> <name> <password>bash$ cdc_users.py [-h] USER PASSWORDbash$ cdc_users.py user1 pass1 >> /var/lib/maxscale/avro-service/cdcusers[Read-Write-Listener]
type=listener
address=::
service=Read-Write-Service
authenticator=ed25519authauthenticator_options=ed_mode=sha256authenticator_options=ed_mode=sha256,
ed_rsa_privkey_path=/tmp/sha_private_key.pem,
ed_rsa_pubkey_path=/tmp/sha_public_key.pem[Read-Write-Listener]
type=listener
address=::
service=Read-Write-Service
authenticator=ed25519auth,mariadbauth
user_mapping_file=/home/joe/mapping.json{
"user_map": [
{
"original_user": "alpha",
"mapped_user": "beta"
},
{
"original_user": "gamma",
"mapped_user": "gamma"
}
],
"server_credentials": [
{
"mapped_user": "beta",
"password": "hunter2",
"plugin": "mysql_native_password"
},
{
"mapped_user": "gamma",
"password": "letmein",
"plugin": "ed25519"
}
]
}[Read-Write-Listener]
type=listener
address=::
service=Read-Write-Service
authenticator=ed25519auth
authenticator_options=ed_mode=sha256
ssl=true
ssl_key=/tmp/my-key.pem
ssl_cert=/tmp/my-cert.pem
ssl_ca=/tmp/myCA.pem[Read-Write-Listener]
type=listener
address=::
service=Read-Write-Service
authenticator=ed25519auth
authenticator_options=ed_mode=sha256,
ed_rsa_privkey_path=/tmp/sha_private_key.pem,
ed_rsa_pubkey_path=/tmp/sha_public_key.pemopenssl genrsa -out sha_private_key.pem 2048
openssl rsa -in sha_private_key.pem -pubout -out sha_public_key.pemBEGIN and START TRANSACTION SQL commands withSTART TRANSACTION READ ONLY. If the transaction is fully read-only, the
transaction completes normally. However, if a write happens in the middle of a
transaction, the filter issues a ROLLBACK command and then replays the
read-only part of the transaction, including the original BEGIN statement. If
the results of the replayed read-only part of the transaction is identical to
the one that was returned to the client, the transaction proceeds normally. If
the result checksum does not match, the connection is closed to prevent a write
with the wrong transaction state from happening.[OptimisticTrx]
type=filter
module=optimistictrx
[MyService]
...
filters=OptimisticTrx$ sudo groupadd maxscale
$ sudo useradd -g maxscale maxscale
$ cd /usr/local
$ sudo tar -xzvf maxscale-x.y.z.OS.tar.gz
$ sudo ln -s maxscale-x.y.z.OS maxscale
$ cd maxscale
$ sudo chown -R maxscale var$ sudo mkdir /var/log/maxscale
$ sudo mkdir /var/lib/maxscale
$ sudo mkdir /run/maxscale
$ sudo mkdir /var/cache/maxscale$ sudo chown maxscale /var/log/maxscale
$ sudo chown maxscale /var/lib/maxscale
$ sudo chown maxscale /run/maxscale
$ sudo chown maxscale /var/cache/maxscale$ sudo bin/maxscale --user=maxscale -d$ sudo bin/maxscale --user=maxscale --basedir=/usr/local/maxscale -d$ tar -xzvf maxscale-x.y.z.OS.tar.gz$ cd maxscale-x.y.z.OS
$ bin/maxscale -d --basedir=.$ bin/maxscale --help[Splitter-Service]
type=service
router=readwritesplit
servers=dbserv1, dbserv2, dbserv3
user=maxscale
password=maxscale_pw[Splitter-Listener]
type=listener
service=Splitter-Service
port=3306maxctrl create filter OptimisticTrx optimistictrx
maxctrl alter service-filter MyService OptimisticTrx[PsReuse]
type=filter
module=psreuse
[MyService]
...
filters=PsReusesysctl vm.overcommit_memorycat /proc/sys/vm/overcommit_memorytar -caf maxscale-backup.tar.gz /etc/maxscale.cnf /etc/maxscale.cnf.d/ /var/lib/maxscale/CREATE USER 'monitor_user'@'%' IDENTIFIED BY 'my_password';CREATE USER 'monitor_user'@'%' IDENTIFIED BY 'my_password';
GRANT REPLICATION CLIENT ON *.* TO 'monitor_user'@'%';GRANT SUPER, RELOAD on *.* to 'monitor_user'@'%';maxkeysgit clone https://github.com/mariadb-corporation/MaxScale
mkdir build
cd build
../MaxScale/BUILD/install_build_deps.sh
cmake ../MaxScale -DCMAKE_INSTALL_PREFIX=/usr
make
sudo make install
sudo ./postinstmake
LD_LIBRARY_PATH=$PWD/server/core/ make package[concat-service]
type=service
router=cat
servers=dbserv1,dbserv2,dbserv3
user=maxscale
password=maxscale_pwmaxpasswd plainpassword
96F99AA1315BDC3604B006F427DD9484[My-Service]
type=service
router=readconnroute
router_options=master
servers=dbserv1, dbserv2, dbserv3
user=maxscale
password=96F99AA1315BDC3604B006F427DD9484[BinlogFilter]
type=filter
module=binlogfilter
match=/customers[.]/
exclude=/[.]orders/
[BinlogServer]
type=service
router=binlogrouter
server_id=33
filters=BinlogFilter
[BinlogListener]
type=listener
service=BinlogServer
port=4000[MyLogFilter]
type=filter
module=tpmfilter
[MyService]
type=service
router=readconnroute
servers=server1
user=myuser
password=mypasswd
filters=MyLogFilterfilename=/tmp/SqlQueryLogsource=127.0.0.1user=johndelimiter=:::query_delimiter=@@@named_pipe=/tmp/tpmfilter$ echo '1' > /tmp/tpmfilter$ echo '0' > /tmp/tpmfilter[PerformanceLogger]
type=filter
module=tpmfilter
delimiter=:::
query_delimiter=@@@
filename=/var/logs/tpm/perf.log
named_pipe=/tmp/tpmfilter
[Product-Service]
type=service
router=readconnroute
servers=server1
user=myuser
password=mypasswd
filters=PerformanceLogger1484086477::::server1::::root::::3::::0.165@@@@0.108@@@@0.102@@@@0.092@@@@0.121@@@@0.122@@@@0.110@@@@2.081::::UPDATE WAREHOUSE SET W_YTD = W_YTD + 3630.48 WHERE W_ID = 2 @@@@SELECT W_STREET_1, W_STREET_2, W_CITY, W_STATE, W_ZIP, W_NAME FROM WAREHOUSE WHERE W_ID = 2@@@@UPDATE DISTRICT SET D_YTD = D_YTD + 3630.48 WHERE D_W_ID = 2 AND D_ID = 9@@@@SELECT D_STREET_1, D_STREET_2, D_CITY, D_STATE, D_ZIP, D_NAME FROM DISTRICT WHERE D_W_ID = 2 AND D_ID = 9@@@@SELECT C_FIRST, C_MIDDLE, C_LAST, C_STREET_1, C_STREET_2, C_CITY, C_STATE, C_ZIP, C_PHONE, C_CREDIT, C_CREDIT_LIM, C_DISCOUNT, C_BALANCE, C_YTD_PAYMENT, C_PAYMENT_CNT, C_SINCE FROM CUSTOMER WHERE C_W_ID = 2 AND C_D_ID = 9 AND C_ID = 1025@@@@UPDATE CUSTOMER SET C_BALANCE = 1007749.25, C_YTD_PAYMENT = 465215.47, C_PAYMENT_CNT = 203 WHERE C_W_ID = 2 AND C_D_ID = 9 AND C_ID = 1025@@@@INSERT INTO HISTORY (H_C_D_ID, H_C_W_ID, H_C_ID, H_D_ID, H_W_ID, H_DATE, H_AMOUNT, H_DATA) VALUES (9,2,1025,9,2,'2017-01-10 17:14:37',3630.48,'locfljbe xtnfqn')
1484086477::::server1::::root::::6::::0.123@@@@0.087@@@@0.091@@@@0.098@@@@0.078@@@@0.106@@@@0.094@@@@0.074@@@@0.089@@@@0.073@@@@0.098@@@@0.073@@@@0.088@@@@0.072@@@@0.087@@@@0.071@@@@0.085@@@@0.078@@@@0.088@@@@0.098@@@@0.081@@@@0.076@@@@0.082@@@@0.073@@@@0.077@@@@0.070@@@@0.105@@@@0.093@@@@0.088@@@@0.089@@@@0.087@@@@0.087@@@@0.086@@@@1.883::::SELECT C_DISCOUNT, C_LAST, C_CREDIT, W_TAX FROM CUSTOMER, WAREHOUSE WHERE W_ID = 2 AND C_W_ID = 2 AND C_D_ID = 10 AND C_ID = 1267@@@@SELECT D_NEXT_O_ID, D_TAX FROM DISTRICT WHERE D_W_ID = 2 AND D_ID = 10 FOR UPDATE@@@@UPDATE DISTRICT SET D_NEXT_O_ID = D_NEXT_O_ID + 1 WHERE D_W_ID = 2 AND D_ID = 10@@@@INSERT INTO OORDER (O_ID, O_D_ID, O_W_ID, O_C_ID, O_ENTRY_D, O_OL_CNT, O_ALL_LOCAL) VALUES (286871, 10, 2, 1267, '2017-01-10 17:14:37', 7, 1)@@@@INSERT INTO NEW_ORDER (NO_O_ID, NO_D_ID, NO_W_ID) VALUES ( 286871, 10, 2)@@@@SELECT I_PRICE, I_NAME , I_DATA FROM ITEM WHERE I_ID = 24167@@@@SELECT S_QUANTITY, S_DATA, S_DIST_01, S_DIST_02, S_DIST_03, S_DIST_04, S_DIST_05, S_DIST_06, S_DIST_07, S_DIST_08, S_DIST_09, S_DIST_10 FROM STOCK WHERE S_I_ID = 24167 AND S_W_ID = 2 FOR UPDATE@@@@SELECT I_PRICE, I_NAME , I_DATA FROM ITEM WHERE I_ID = 96982@@@@SELECT S_QUANTITY, S_DATA, S_DIST_01, S_DIST_02, S_DIST_03, S_DIST_04, S_DIST_05, S_DIST_06, S_DIST_07, S_DIST_08, S_DIST_09, S_DIST_10 FROM STOCK WHERE S_I_ID = 96982 AND S_W_ID = 2 FOR UPDATE@@@@SELECT I_PRICE, I_NAME , I_DATA FROM ITEM WHERE I_ID = 40679@@@@SELECT S_QUANTITY, S_DATA, S_DIST_01, S_DIST_02, S_DIST_03, S_DIST_04, S_DIST_05, S_DIST_06, S_DIST_07, S_DIST_08, S_DIST_09, S_DIST_10 FROM STOCK WHERE S_I_ID = 40679 AND S_W_ID = 2 FOR UPDATE@@@@SELECT I_PRICE, I_NAME , I_DATA FROM ITEM WHERE I_ID = 31459@@@@SELECT S_QUANTITY, S_DATA, S_DIST_01, S_DIST_02, S_DIST_03, S_DIST_04, S_DIST_05, S_DIST_06, S_DIST_07, S_DIST_08, S_DIST_09, S_DIST_10 FROM STOCK WHERE S_I_ID = 31459 AND S_W_ID = 2 FOR UPDATE@@@@SELECT I_PRICE, I_NAME , I_DATA FROM ITEM WHERE I_ID = 6143@@@@SELECT S_QUANTITY, S_DATA, S_DIST_01, S_DIST_02, S_DIST_03, S_DIST_04, S_DIST_05, S_DIST_06, S_DIST_07, S_DIST_08, S_DIST_09, S_DIST_10 FROM STOCK WHERE S_I_ID = 6143 AND S_W_ID = 2 FOR UPDATE@@@@SELECT I_PRICE, I_NAME , I_DATA FROM ITEM WHERE I_ID = 12001@@@@SELECT S_QUANTITY, S_DATA, S_DIST_01, S_DIST_02, S_DIST_03, S_DIST_04, S_DIST_05, S_DIST_06, S_DIST_07, S_DIST_08, S_DIST_09, S_DIST_10 FROM STOCK WHERE S_I_ID = 12001 AND S_W_ID = 2 FOR UPDATE@@@@SELECT I_PRICE, I_NAME , I_DATA FROM ITEM WHERE I_ID = 40407@@@@SELECT S_QUANTITY, S_DATA, S_DIST_01, S_DIST_02, S_DIST_03, S_DIST_04, S_DIST_05, S_DIST_06, S_DIST_07, S_DIST_08, S_DIST_09, S_DIST_10 FROM STOCK WHERE S_I_ID = 40407 AND S_W_ID = 2 FOR UPDATE@@@@INSERT INTO ORDER_LINE (OL_O_ID, OL_D_ID, OL_W_ID, OL_NUMBER, OL_I_ID, OL_SUPPLY_W_ID, OL_QUANTITY, OL_AMOUNT, OL_DIST_INFO) VALUES (286871,10,2,1,24167,2,7,348.31998,'btdyjesowlpzjwnmxdcsion')@@@@INSERT INTO ORDER_LINE (OL_O_ID, OL_D_ID, OL_W_ID, OL_NUMBER, OL_I_ID, OL_SUPPLY_W_ID, OL_QUANTITY, OL_AMOUNT, OL_DIST_INFO) VALUES (286871,10,2,2,96982,2,1,4.46,'kudpnktydxbrbxibbsyvdiw')@@@@INSERT INTO ORDER_LINE (OL_O_ID, OL_D_ID, OL_W_ID, OL_NUMBER, OL_I_ID, OL_SUPPLY_W_ID, OL_QUANTITY, OL_AMOUNT, OL_DIST_INFO) VALUES (286871,10,2,3,40679,2,7,528.43,'nhcixumgmosxlwgabvsrcnu')@@@@INSERT INTO ORDER_LINE (OL_O_ID, OL_D_ID, OL_W_ID, OL_NUMBER, OL_I_ID, OL_SUPPLY_W_ID, OL_QUANTITY, OL_AMOUNT, OL_DIST_INFO) VALUES (286871,10,2,4,31459,2,9,341.82,'qbglbdleljyfzdpfbyziiea')@@@@INSERT INTO ORDER_LINE (OL_O_ID, OL_D_ID, OL_W_ID, OL_NUMBER, OL_I_ID, OL_SUPPLY_W_ID, OL_QUANTITY, OL_AMOUNT, OL_DIST_INFO) VALUES (286871,10,2,5,6143,2,3,152.67,'tmtnuupaviimdmnvmetmcrc')@@@@INSERT INTO ORDER_LINE (OL_O_ID, OL_D_ID, OL_W_ID, OL_NUMBER, OL_I_ID, OL_SUPPLY_W_ID, OL_QUANTITY, OL_AMOUNT, OL_DIST_INFO) VALUES (286871,10,2,6,12001,2,5,304.3,'ufytqwvkqxtmalhenrssfon')@@@@INSERT INTO ORDER_LINE (OL_O_ID, OL_D_ID, OL_W_ID, OL_NUMBER, OL_I_ID, OL_SUPPLY_W_ID, OL_QUANTITY, OL_AMOUNT, OL_DIST_INFO) VALUES (286871,10,2,7,40407,2,1,30.32,'hvclpfnblxchbyluumetcqn')@@@@UPDATE STOCK SET S_QUANTITY = 65 , S_YTD = S_YTD + 7, S_ORDER_CNT = S_ORDER_CNT + 1, S_REMOTE_CNT = S_REMOTE_CNT + 0 WHERE S_I_ID = 24167 AND S_W_ID = 2@@@@UPDATE STOCK SET S_QUANTITY = 97 , S_YTD = S_YTD + 1, S_ORDER_CNT = S_ORDER_CNT + 1, S_REMOTE_CNT = S_REMOTE_CNT + 0 WHERE S_I_ID = 96982 AND S_W_ID = 2@@@@UPDATE STOCK SET S_QUANTITY = 58 , S_YTD = S_YTD + 7, S_ORDER_CNT = S_ORDER_CNT + 1, S_REMOTE_CNT = S_REMOTE_CNT + 0 WHERE S_I_ID = 40679 AND S_W_ID = 2@@@@UPDATE STOCK SET S_QUANTITY = 28 , S_YTD = S_YTD + 9, S_ORDER_CNT = S_ORDER_CNT + 1, S_REMOTE_CNT = S_REMOTE_CNT + 0 WHERE S_I_ID = 31459 AND S_W_ID = 2@@@@UPDATE STOCK SET S_QUANTITY = 86 , S_YTD = S_YTD + 3, S_ORDER_CNT = S_ORDER_CNT + 1, S_REMOTE_CNT = S_REMOTE_CNT + 0 WHERE S_I_ID = 6143 AND S_W_ID = 2@@@@UPDATE STOCK SET S_QUANTITY = 13 , S_YTD = S_YTD + 5, S_ORDER_CNT = S_ORDER_CNT + 1, S_REMOTE_CNT = S_REMOTE_CNT + 0 WHERE S_I_ID = 12001 AND S_W_ID = 2@@@@UPDATE STOCK SET S_QUANTITY = 44 , S_YTD = S_YTD + 1, S_ORDER_CNT = S_ORDER_CNT + 1, S_REMOTE_CNT = S_REMOTE_CNT + 0 WHERE S_I_ID = 40407 AND S_W_ID = 2
...INSERT INTO departments VALUES ('d1234', 'NewDepartment'); -- maxscale ccr=ignorematch=.*INSERT.*
ignore=.*UPDATE.*
options=case,extended[CCRFilter]
type=filter
module=ccrfilter
time=5sudo yum -y install epel-release
sudo yum -y install jansson openssl-devel cmake make gcc-c++ gitsudo apt-get update
sudo apt-get -y install libjansson-dev libssl-dev cmake make g++ gitsudo apt-get update
sudo apt-get -y install libjansson-dev libssl-dev cmake make g++ gitsudo zypper install -y libjansson-devel openssl-devel cmake make gcc-c++ gitauthenticator=GSSAPIAuth
authenticator_options=principal_name=mariadb/localhost.localdomain@EXAMPLE.COMauthenticator_options=principal_name=mymariadb@EXAMPLE.COM,gssapi_keytab_path=/home/user/mymariadb.keytab