Here are the steps that use four terminal windows to reset MariaDB database replication (when not using an external database):
Note: The steps assume two statefulsets named codedx-mariadb-master and codedx-mariadb-slave and a deployment named codedx in the cdx-app namespace with one subordinate database.
Terminal 1 (Subordinate DB):
- kubectl -n cdx-app scale --replicas=0 deployment/codedx
- kubectl -n cdx-app exec -it codedx-mariadb-slave-0 -- bash
- mysql -uroot -p
- STOP SLAVE;
- exit # mysql
Terminal 2 (Master DB):
- kubectl -n cdx-app exec -it codedx-mariadb-master-0 -- bash
- mysql -uroot -p
- RESET MASTER;
Note: RESET MASTER deletes previous binary log files, creating a new binary log file.
- FLUSH TABLES WITH READ LOCK;
Terminal 3 (Master DB):
- kubectl -n cdx-app exec -it codedx-mariadb-master-0 -- bash
- mysqldump -u root -p codedx > /bitnami/mariadb/codedx-dump.sql
Note: The above command assumes you have adequate space at /bitnami/mariadb to store your database backup. Use an alternate path as necessary, and adjust paths in subsequent steps accordingly.
Terminal 2 (Master DB)
- UNLOCK TABLES;
Terminal 4:
- kubectl -n cdx-app cp codedx-mariadb-master-0:/bitnami/mariadb/codedx-dump.sql ./codedx-dump.sql
- kubectl -n cdx-app cp ./codedx-dump.sql codedx-mariadb-slave-0:/bitnami/mariadb/codedx-dump.sql
Terminal 1 (Subordinate DB):
- mysql -u root -p codedx < /bitnami/mariadb/codedx-dump.sql
- mysql -uroot -p
- RESET SLAVE;
Note: RESET SLAVE deletes relay log files.
- Remove old binary log files by running "SHOW BINARY LOGS;" and "PURGE BINARY LOGS TO 'name';"
Note: If you previously deleted binary log files (mysql-bin.000*) from the file system, remove the contents of the mysql-bin.index text file.
- CHANGE MASTER TO MASTER_LOG_FILE='mysql-bin.000001', MASTER_LOG_POS=1;
- START SLAVE;
- SHOW SLAVE STATUS \G;
- exit # mysql
- rm /bitnami/mariadb/codedx-dump.sql
- exit # pod
- exit # terminal
Terminal 2 (Master DB):
- exit # mysql
- rm /bitnami/mariadb/codedx-dump.sql
- exit # pod
- exit # terminal
Terminal 3 (Master DB):
- exit # pod
- exit # terminal
Terminal 4:
- kubectl -n cdx-app scale --replicas=1 deployment/codedx
- exit # terminal