Docker

docker 下的 mysql主从

2018-11-06  本文已影响28人  Royalknight

本篇打算创建一个 1主2从的 mysql主从,3个docker容器

D:.                
├─master           
│  └─conf          
│          my.cnf  
├─slave1           
│  └─conf          
│          my.cnf  
└─slave2           
    └─conf         
            my.cnf 

进入 master-mysql 实例
docker exec -it master-mysql bash
进入后 连接进入mysql 创建库先放入一些数据,

 ~:mysql -uroto -proot
 mysql> create database newplan DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci
    -> ;
Query OK, 1 row affected, 2 warnings (0.03 sec)utf8_general_ci;
mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| newplan            |
| performance_schema |
| sys                |
+--------------------+
5 rows in set (0.00 sec)


log-bin=mysql-bin
server-id=1
binlog-do-db=newplan
CREATE USER 'leven'@'localhost' IDENTIFIED BY 'Leven';#创建用户
GRANT REPLICATION SLAVE ON *.* TO 'leven'@'localhost';#授权
flush privileges; 
show master status;
+------------------+----------+--------------+------------------+-------------------+
| File             | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |
+------------------+----------+--------------+------------------+-------------------+
| mysql-bin.000002 |    10622 | newplan      |                  |                   |
+------------------+----------+--------------+------------------+-------------------+
1 row in set (0.00 sec)                                                              

到此主库的配置基本完毕


docker exec -it slave1-mysql bash
mysql -uroot -proot
stop slave;
set global sql_slave_skip_counter=1;
start slave;

参考资料:
https://blog.csdn.net/m0_37890289/article/details/80087003
https://store.docker.com/images/mysql
https://dev.mysql.com/doc/relnotes/mysql/8.0/en/

上一篇 下一篇

猜你喜欢

热点阅读