High availability for a MySQL or MariaDB endpoint reduces downtime by keeping the database service and its client-facing address together during node failure or maintenance. Applications continue using the same host or IP while the cluster relocates the active instance.
The pcs CLI configures Pacemaker resources for a floating IP plus the database daemon. An ocf:heartbeat:IPaddr2 resource adds the floating address, a systemd resource controls the database unit, and a resource group enforces colocation and ordered start/stop so the IP exists before the daemon starts.
Failover moves the service and address; it does not replicate database data. Ensure the storage or replication design keeps the data directory consistent across nodes, and enable fencing to prevent split-brain. Planned failover tests should occur during a maintenance window because active sessions drop during stop/start.
Steps to set up MySQL or MariaDB high availability with PCS:
- Confirm the cluster is online with quorum.
$ sudo pcs status Cluster name: clustername Cluster Summary: * Stack: corosync (Pacemaker is running) * Current DC: node-01 (version 2.1.6-6fdc9deea29) - partition with quorum * Last updated: Thu Jan 1 05:39:07 2026 on node-01 * Last change: Thu Jan 1 05:39:05 2026 by root via cibadmin on node-01 * 3 nodes configured * 0 resource instances configured Node List: * Online: [ node-01 node-02 node-03 ] Full List of Resources: * No resources Daemon Status: corosync: active/enabled pacemaker: active/enabled pcsd: active/enabled
- Identify the database service unit name on each node.
$ systemctl list-unit-files --type=service | grep -E '^(mysql|mysqld|mariadb)\.service' mariadb.service disabled enabled mysql.service alias - mysqld.service alias -
- Disable standalone startup for the database service unit on each node.
$ sudo systemctl disable --now mariadb Synchronizing state of mariadb.service with SysV service script with /usr/lib/systemd/systemd-sysv-install. Executing: /usr/lib/systemd/systemd-sysv-install disable mariadb Synchronizing state of mariadb.service with SysV service script with /usr/lib/systemd/systemd-sysv-install. Executing: /usr/lib/systemd/systemd-sysv-install disable mariadb Synchronizing state of mariadb.service with SysV service script with /usr/lib/systemd/systemd-sysv-install. Executing: /usr/lib/systemd/systemd-sysv-install disable mariadb
Stopping the database service interrupts active connections.
- Create a floating IP resource for the database endpoint.
$ sudo pcs resource create db_ip ocf:heartbeat:IPaddr2 ip=192.0.2.20 cidr_netmask=24 op monitor interval=30s
Set nic=<interface> when multiple network interfaces exist.
- Create the database service resource under systemd control.
$ sudo pcs resource create db_service systemd:mariadb op start timeout=120s op stop timeout=120s op monitor interval=30s
Use systemd:mysqld or systemd:mysql when those units are present.
- Create a resource group for the floating IP resource plus the database service resource.
$ sudo pcs resource group add db-stack db_ip db_service
- Verify the resource group is started on a single node.
$ sudo pcs status resources * Resource Group: db-stack: * db_ip (ocf:heartbeat:IPaddr2): Started node-01 * db_service (systemd:mariadb): Started node-01 - Verify the floating IP address is present on the active node.
$ ip -brief address show lo UNKNOWN 127.0.0.1/8 ::1/128 ##### snipped ##### eth0@if456 UP 192.0.2.11/24 192.0.2.20/24
- Verify the database service is listening on the expected port on the active node.
$ sudo ss --tcp --listening --numeric --processes State Recv-Q Send-Q Local Address:Port Peer Address:PortProcess LISTEN 0 80 0.0.0.0:3306 0.0.0.0:* users:(("mariadbd",pid=196578,fd=24)) ##### snipped ##### - Run a failover test for the resource group.
Mohd Shakir Zakaria is a cloud architect with deep roots in software development and open-source advocacy. Certified in AWS, Red Hat, VMware, ITIL, and Linux, he specializes in designing and managing robust cloud and on-premises infrastructures.
