mysql主机master
1. 编辑mysql配置文件my.cnf
server_id = 1 #server_id服务器唯一标识
log_bin = mysql-bin #借助mysql配置文件打开binlog
重启mysql
2.创建一个用于主从复制的用户
mysql> create user ‘repl‘@‘172.17.0.%‘ identified by ‘abcd_123‘;
授权:
mysql> grant replication slave on *.* to ‘repl‘@‘172.17.0.%‘ identified by ‘abcd_123‘;
mysql> flush privileges;
查看主机状态:
mysql> show master status;
mysql>show slave status/G;
mysql从机slave
1. mysql> stop slave; //停止主从复制
2. 同步
mysql> change master to master_host=‘172.17.0.2‘, master_user=‘repl‘, master_password=‘abcd_123‘, master_log_file=‘mysql-bin.000001‘, master_log_pos=575;
3. mysql> start slave;
docker下命令
docker inspect mysql master|grep IP