$ docker exec -it mysql-master mysql -u root -p
Enter password: my_root_password
mysql> CREATE USER 'repl'@'%' IDENTIFIED BY 'password';mysql> GRANT REPLICATION SLAVE ON *.* TO 'repl'@'%';
将Slave和Master关联
到Slave上把自己和Master关联起来:
1
2
3
4
5
6
7
8
9
10
$ docker exec -it mysql-slave-1 mysql -u root -p
Enter password: my_root_password
mysql> CHANGE MASTER TO
MASTER_HOST='192.168.101.21',
MASTER_PORT=3307,
MASTER_USER='repl',
MASTER_PASSWORD='password',
GET_MASTER_PUBLIC_KEY=1,
MASTER_AUTO_POSITION=1;
CHANGE MASTER TO
MASTER_HOST='mysql-master',
MASTER_PORT=3306,
MASTER_USER='repl',
MASTER_PASSWORD='password',
GET_MASTER_PUBLIC_KEY=1,
MASTER_AUTO_POSITION=1;
Troubleshooting
docker run版本在Mac上无法工作
这个是因为Slave容器无法访问到Master的host。解决办法我也不知道。
关于GET_MASTER_PUBLIC_KEY
在做本例子时出现过Slave无法连接到Master的情况:
1
2
3
4
5
6
2019-06-19T01:34:24.361566Z 8 [System] [MY-010597] [Repl] 'CHANGE MASTER TO FOR CHANNEL '' executed'. Previous state master_host='', master_port= 3306, master_log_file='', master_log_pos= 4, master_bind=''. New state master_host='mysql-master', master_port= 3306, master_log_file='', master_log_pos= 4, master_bind=''.
2019-06-19T01:34:28.274728Z 9 [Warning] [MY-010897] [Repl] Storing MySQL user name or password information in the master info repository is not secure and is therefore not recommended. Please consider using the USER and PASSWORD connection options for START SLAVE; see the 'START SLAVE Syntax' in the MySQL Manual for more information.
2019-06-19T01:34:28.330825Z 9 [ERROR] [MY-010584] [Repl] Slave I/O for channel '': error connecting to master 'repl@mysql-master:3306' - retry-time: 60 retries: 1, Error_code: MY-002061
2019-06-19T01:35:28.333735Z 9 [ERROR] [MY-010584] [Repl] Slave I/O for channel '': error connecting to master 'repl@mysql-master:3306' - retry-time: 60 retries: 2, Error_code: MY-002061
2019-06-19T01:36:28.335525Z 9 [ERROR] [MY-010584] [Repl] Slave I/O for channel '': error connecting to master 'repl@mysql-master:3306' - retry-time: 60 retries: 3, Error_code: MY-002061
...
评论