master-slave synchronization docker mySql

As used herein mysql5.6.

docker pull mysql:5.6

Mysql_1.cnf created in the root directory: 

Main Configuration Library
[mysqld]
log-bin bin = MySQL-
Server-ID. 1 =

Mysql_2.cnf created in the root directory:

 

Configuration from the library
[mysqld]
log-bin bin = MySQL-
Server-ID = 2

 

root password is 123456

docker run --name mysql_1 -v /root/mysql_1.cnf:/etc/mysql/my.cnf -p 3307:3306 -e MYSQL_ROOT_PASSWORD=123456 -d mysql:5.6

docker exec -it mysql_1 /bin/bash

docker run --name mysql_2 -v /root/mysql_2.cnf:/etc/mysql/my.cnf -p 3308:3306 -e MYSQL_ROOT_PASSWORD=123456 -d mysql:5.6

docker exec -it mysql_2 /bin/bash

Creating a user sync in the main library.

create user 'sync'@'%' identified by '123';

Main Library execution

grant all privileges on *.* to 'sync'@'%' identified by '123456' with grant option;

flush privileges;

Here logfile field master_log_file will be used from the library.

show master status;

See container docker IP
docker --format Inspect '{} {} .NetworkSettings.IPAddress' mysql_1

docker inspect --format '{{.NetworkSettings.IPAddress}}' mysql_2

Execution from the library
stop slave;

ip user host-based library-based logfile created in the library of the main library status statement results File
Change Master to MASTER_HOST = '172.17.0.3', MASTER_USER = 'Sync', master_password = '123456', MASTER_LOG_FILE = ' mysql-bin.000004 ';

start slave;

show slave status;

When Slave_IO_Running Slave_SQL_Running are successful Yes

Guess you like

Origin www.cnblogs.com/lpl1/p/11223444.html