Skip to content

Instantly share code, notes, and snippets.

@chrispage1
Last active December 7, 2020 15:50
Show Gist options
  • Save chrispage1/ea5005b3a2876f0379d205cc0504aaa0 to your computer and use it in GitHub Desktop.
Save chrispage1/ea5005b3a2876f0379d205cc0504aaa0 to your computer and use it in GitHub Desktop.
Useful MariaDB/Maxscale actions & commands

MariaDB

Backing up MariaDB database using mariadb-backup

# backup to mariadb-bkp directory
mkdir mariadb-bkp && cd mariadb-bkp
mariadb-backup --backup --target-dir=.

# prepare a backup for restore
mariadb-backup --prepare --target-dir=.

# restore a backup
systemctl stop mariadb
rm -rf /var/lib/mysql/*
mariadb-backup --move-back --target-dir=. --datadir=/var/lib/mysql
chown -R mysql:mysql /var/lib/mysql
systemctl start mysql

Bringing slave back into cluster

The GTID can be found in the xtrabackup_binlog_info file. E.g. mariadb-bin.000002 54000173 0-92-441693. You would then use the 0-92-441693 GTID as the MASTER_GTID.

set global gtid_slave_pos='MASTER_GTID';
change master to master_host='MASTER_IP', master_user='maxscale_monitor', master_password='DB_PASSWORD', master_port=3307, master_use_gtid=slave_pos;
start slave;
show slave status\G;

Manually changing a slaves master

mysql -u admin -p

> stop slave;
> CHANGE MASTER TO MASTER_HOST='<new master>'
> start slave;
> show slave status\G;

MaxScale

Manually switching MaxScale active node using switchover

maxctrl -u user --password='password'

> list monitors
> list servers

> call command mariadbmon switchover <monitor name> <new_master> <old_master>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment