docker下 mysql主从配置

1、主从

1、  [mysqld]

log-bin=mysql-bin

server-id=101

[mysqld]

log-bin=mysql-bin

server-id=102


2、启动

docker create --name primary -v /usr/local/application/mysql/data/primary:/var/lib/mysql  -v /usr/local/application/mysql/primary:/etc/mysql/conf.d -e MYSQL_ROOT_PASSWORD=123456 -p 3306:3306 mysql:5.7

docker create --name secondary -v /usr/local/application/mysql/data/secondary:/var/lib/mysql  -v /usr/local/application/mysql/secondary:/etc/mysql/conf.d -e MYSQL_ROOT_PASSWORD=123456 -p 3307:3306 mysql:5.7


3、连接主

CREATE USER 'repl'@'101.200.152.192' IDENTIFIED BY '123456';

GRANT REPLICATION SLAVE ON *.* TO 'repl'@'%' IDENTIFIED BY '123456';

SHOW MASTER STATUS;


4、连接从

CHANGE MASTER TO

MASTER_HOST='101.200.152.192',

MASTER_USER='repl',

MASTER_PASSWORD='123456',

MASTER_LOG_FILE='mysql-bin.000003',

master_port=3306,

MASTER_LOG_POS=702;


5.手工启动slave复制线程

start slave

6.再次查看下slave状态

show slave status \G

这回都YES,配置完成,顺便看看进程

mysql> show processlist;

你可能感兴趣的:(docker下 mysql主从配置)