diff --git a/bitnami/mysql/8.0/debian-11/rootfs/opt/bitnami/scripts/libmysql.sh b/bitnami/mysql/8.0/debian-11/rootfs/opt/bitnami/scripts/libmysql.sh index 192984bec0a0c..10a13c8d416bb 100644 --- a/bitnami/mysql/8.0/debian-11/rootfs/opt/bitnami/scripts/libmysql.sh +++ b/bitnami/mysql/8.0/debian-11/rootfs/opt/bitnami/scripts/libmysql.sh @@ -178,6 +178,65 @@ pid_file=${DB_PID_FILE} EOF } +######################## +# Make a dump on master database and update slave database +# Globals: +# DB_* +# Arguments: +# None +# Returns: +# None +######################### +mysql_exec_initial_dump() { + info "MySQL dump master data start..." + + mysql -h "$DB_MASTER_HOST" -P "$DB_MASTER_PORT_NUMBER" -u "$DB_MASTER_ROOT_USER" -p"$DB_MASTER_ROOT_PASSWORD" -e 'RESET MASTER;' + + databases=("mysql") + + if [ -n "$DB_DATABASE" ]; then + databases+=("$DB_DATABASE") + fi + + for DB in "${databases[@]}"; do + info "Start dump process database $DB" + + if [[ $DB = @(information_schema|performance_schema|sys) ]]; then + info "Skipping default table $DB to be imported" + continue + fi + + FILE_LOCATION="$DB_DATA_DIR/dump_$DB.sql" + + mysqldump --verbose -h "$DB_MASTER_HOST" -P "$DB_MASTER_PORT_NUMBER" -u "$DB_MASTER_ROOT_USER" -p"$DB_MASTER_ROOT_PASSWORD" $DB > $FILE_LOCATION + + info "Finish dump database $DB" + + if [ $? -eq 0 ]; then + info "Ensure database exists $DB" + + mysql -u "$DB_MASTER_ROOT_USER" < $FILE_LOCATION + + info "Finish dump database $DB" + + if [ $? -eq 0 ]; then + info "Ensure database exists $DB" + + mysql -u "$DB_MASTER_ROOT_USER" < **Note**: You should not scale up/down the number of master nodes. Always have only one master node running. +If your master database is missing some binary files, the replication will break. It's possible to add `MYSQL_REPLICATION_SLAVE_DUMP=true` to make a dump on the master and import it on the slave. + +> **Note**: The master database must be only used by this process until the end to avoid missing data. +> **Note**: This process will use "RESET MASTER" on the master database, removing all binary log files that are listed in the index file. It is recommended to make a backup of binary files to avoid possible data loss, in case something goes wrong. + ### Configuration file The image looks for user-defined configurations in `/opt/bitnami/mysql/conf/my_custom.cnf`. Create a file named `my_custom.cnf` and mount it at `/opt/bitnami/mysql/conf/my_custom.cnf`. diff --git a/bitnami/mysql/docker-compose-replication.yml b/bitnami/mysql/docker-compose-replication.yml index 8bf07b34e965b..0983eeddc7a78 100644 --- a/bitnami/mysql/docker-compose-replication.yml +++ b/bitnami/mysql/docker-compose-replication.yml @@ -40,6 +40,8 @@ services: - MYSQL_MASTER_ROOT_PASSWORD=my_root_password # ALLOW_EMPTY_PASSWORD is recommended only for development. - ALLOW_EMPTY_PASSWORD=yes + # In case of missing binary files on master, use `true` to reset those binary files. Creating a previous backup is recommended. + - MYSQL_REPLICATION_SLAVE_DUMP=false healthcheck: test: ['CMD', '/opt/bitnami/scripts/mysql/healthcheck.sh'] interval: 15s