为了理解 mariadb 复制,我创建了下一个 docker 容器:
docker run -e TZ=America/Denver --name mariadb1 --network=camino_nw \
-e MARIADB_SERVER_ID=1 -e MARIADB_LOG_BIN=mysql-bin -e MARIADB_LOG_BASENAME=mariadb1 \
-e MARIADB_BINLOG_FORMAT=mixed -p 127.0.0.1:53301:3306 \
-v /home/jcz/Documents/dockerMariadbData1:/var/lib/mysql:z \
-e MARIADB_ROOT_PASSWORD=S3cretPw -d mariadb:latest
docker run -e TZ=America/Denver --name mariadb2 --network=camino_nw \
-e MARIADB_SERVER_ID=2 -e MARIADB_LOG_BIN=mysql-bin -e MARIADB_LOG_BASENAME=mariadb2 \
-e MARIADB_BINLOG_FORMAT=mixed -p 127.0.0.1:53302:3306 \
-v /home/jcz/Documents/dockerMariadbData2:/var/lib/mysql:z \
-e MARIADB_ROOT_PASSWORD=S3cretPw -d mariadb:latest
docker run -e TZ=America/Denver --name mariadb3 --network=camino_nw \
-e MARIADB_SERVER_ID=3 -e MARIADB_LOG_BIN=mysql-bin -e MARIADB_LOG_BASENAME=mariadb3 \
-e MARIADB_BINLOG_FORMAT=mixed -p 127.0.0.1:53303:3306 \
-v /home/jcz/Documents/dockerMariadbData3:/var/lib/mysql:z \
-e MARIADB_ROOT_PASSWORD=S3cretPw -d mariadb:latest
主服务器是 mariadb1,对于这个我执行了:
CREATE USER 'replication_user'@'%' IDENTIFIED BY 'S3cretPw';
GRANT REPLICATION SLAVE ON *.* TO 'replication_user'@'%';
对于每个从属 mariadb2 和 mariadb3 我运行:
CHANGE MASTER TO MASTER_HOST='mariadb1', MASTER_USER='replication_user', MASTER_PASSWORD='S3cretPw', MASTER_PORT=3306, MASTER_CONNECT_RETRY=10;
CHANGE MASTER TO MASTER_USE_GTID = slave_pos;
我还用 START SLAVE 启动了从属服务器;
运行
SHOW SLAVE STATUS \G
我收到下一个错误:
Last_IO_Error: Fatal error: The slave I/O thread stops because master and slave have equal MariaDB server ids; these ids must be different for replication to work (or the --replicate-same-server-id option must be used on slave but this does not always make sense; please check the manual before using it).
如果我使用,怎么会发生这种情况
MARIADB_SERVER_ID=1
MARIADB_SERVER_ID=2
MARIADB_SERVER_ID=3
对于我的每个容器?
我正在尝试遵循: