2

I've been trying to get two databases in docker containers to replicate. I've been working off this article: https://www.digitalocean.com/community/tutorials/how-to-set-up-master-slave-replication-in-mysql (and others).

The state I've been able to get to is that the master and slave dbs have loaded cnf files that set the server-ids, and after the DBs are stood up, I am able to run a few commands that should get the DBs to be connected:

MS_STATUS=`docker exec mysql-master sh -c 'export MYSQL_PWD=password; mysql -u root -e "SHOW MASTER STATUS"'`
CURRENT_LOG=`echo $MS_STATUS | awk '{print $6}'`
CURRENT_POS=`echo $MS_STATUS | awk '{print $7}'`

start_slave_stmt="CHANGE MASTER TO MASTER_HOST='mysql-master',MASTER_USER='replication_user',MASTER_PASSWORD='replicationPW',MASTER_LOG_FILE='$CURRENT_LOG',MASTER_LOG_POS=$CURRENT_POS; START SLAVE;"

start_slave_cmd='export MYSQL_PWD=password; mysql -u root -e "'

start_slave_cmd+="$start_slave_stmt"

start_slave_cmd+='"'

docker exec mysql-slave sh -c "$start_slave_cmd"

This sets the master_log_file and Read_master_log_pos to the same values in both the master and slave dbs.

The error I am getting is:

mysql-slave               | 2018-09-20T20:13:41.547886Z 11 [ERROR] [MY-010584] [Repl] Slave I/O for channel '': error connecting to master 'replication_user@mysql-master:3306' - retry-time: 60  retries: 1, Error_code: MY-002061

I've looked at the documentation, but I don't see any mention of that error code (2061). What am I missing?

I've named the replication user in both database the same... could that be the issue?

  • Its a network problem between docker containers. Try to connect to the master 3306 port from your docker slave container. Are you using docker-compose to start them in the same namespace? Or exposed ports? – danblack Sep 20 '18 at 23:04
  • I have a port forwarded to the host in the docker-compose. Is that different from opening internally. – Jeff Sep 20 '18 at 23:30
  • @danblack do I need additional login rights beyond replication? I was able to login via mysql -h mysql-master -u replication_user -p – Jeff Sep 21 '18 at 16:03
  • a replication user should be able to connect. – danblack Sep 21 '18 at 21:04
  • I was able to do that. – Jeff Sep 21 '18 at 21:07
2

Also, you just can run

CHANGE MASTER TO GET_MASTER_PUBLIC_KEY=1;

but this solution has a restriction (see the documentation https://dev.mysql.com/doc/refman/8.0/en/caching-sha2-pluggable-authentication.html)

Use of a trusted local copy of the public key enables the client to avoid a round trip in the client/server protocol, and is more secure than requesting the public key from the server. On the other hand, requesting the public key from the server is more convenient (it requires no management of a client-side file) and may be acceptable in secure network environments.

0

On the master SHOW GLOBAL VARIABLES LIKE 'caching_sha2_password_public_key_path'. Copy that file to the slave.

On the slave, use the CHANGE MASTER TO statement with the MASTER_PUBLIC_KEY_PATH option to specify the RSA public key file

0
  1. MY-002061 - it`s problem authentication;
  2. When creating a User, you must explicitly specify the authentication plugin sha256_password;
  3. For example: CREATE USER 'slaveuser'@'%' IDENTIFIED WITH sha256_password BY '0000';
  4. Then: GRANT REPLICATION SLAVE ON *.* TO 'slaveuser'@'%';
  5. After that, of course, re-create everything.

Your Answer

By clicking "Post Your Answer", you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.