22/04/2022
docker mysql master slave - marche pas en mysql 8

marche avec mysql 5

https://github.com/vbabak/docker-mysql-master-slave/blob/master/build.sh

tentative mysql 8 qui marche pas :

rm -rf /root/docker/mysql_slave /root/docker/mysql_master
docker rm -f mysql_master mysql_slave
mkdir -p /root/docker/mysql_slave/data /root/docker/mysql_master/data
chown 999:999 /root/docker/mysql_slave/data /root/docker/mysql_master/data

# MASTER
########

cat - > /root/docker/mysql_master/myconfig.cnf <<EOF
[mysqld]
# skip-host-cache
# skip-name-resolve
server-id = 1
log_bin = /var/log/mysql/mysql-bin.log
binlog_format = ROW
binlog_do_db = mydb
EOF

docker run -p 5506:3306 --name mysql_master \
-e MYSQL_ROOT_PASSWORD=V9rVVfjAfdTIs6mT \
-v /root/docker/mysql_master/data:/var/lib/mysql \
-d mysql

# wait up

docker rm -f mysql_master
docker run -p 5506:3306 --name mysql_master \
-e MYSQL_ROOT_PASSWORD=V9rVVfjAfdTIs6mT \
-v /root/docker/mysql_master/data:/var/lib/mysql \
-v /root/docker/mysql_master/myconfig.cnf:/etc/mysql/conf.d/myconfig.cnf \
-d mysql


# # sur le master on crée un user pour que le slave puisse se connecter
# docker exec -ti mysql_slave mysql -u root -pV9rVVfjAfdTIs6mT;
# CREATE USER 'rootslave'@'%' IDENTIFIED WITH mysql_native_password BY 'V9rVVfjAfdTIs6mT';
# grant replication slave on *.* to 'rootslave'@'%'?
# # peut etre : docker restart mysql_master

# # check
# docker exec -ti mysql_master mysql -u root -pV9rVVfjAfdTIs6mT;
# show master status;

# # SLAVE
# #########
# cat - > /root/docker/mysql_slave/myconfig.cnf <<EOF
# [mysqld]
# skip-host-cache
# skip-name-resolve
# server-id=2
# relay-log = /var/log/mysql/mysql-relay-bin.log
# log_bin = /var/log/mysql/mysql-bin.log
# binlog_do_db = mydb
# EOF

# docker run -p 4406:3306 --name mysql_slave \
# -v /root/docker/mysql_master/myconfig.cnf:/etc/mysql/conf.d/myconfig.cnf \
# -v /root/docker/mysql_master/data:/var/lib/mysql \
# -e MYSQL_ROOT_PASSWORD=V9rVVfjAfdTIs6mT \
# -d mysql

# # sur le master on crée un user pour que le slave puisse se connecter
# docker exec -ti mysql_slave mysql -u root -pV9rVVfjAfdTIs6mT;
# CHANGE MASTER TO MASTER_HOST='mysql_master',MASTER_USER='mydb_slave_user',MASTER_PASSWORD='mydb_slave_pwd',MASTER_LOG_FILE='$CURRENT_LOG',MASTER_LOG_POS=$CURRENT_POS; START SLAVE;
# # peut etre : docker restart mysql_slave
# show slave status;