MySQL -- 基于Docker搭建主从集群
目录结构
1 | $ tree |
master.cnf
1 | [mysqld] |
slave.cnf
1 | [mysqld] |
启动容器
1 | $ docker run --name mysql_master -d -e MYSQL_ROOT_PASSWORD=123456 -v ~/mysql/master/data:/var/lib/mysql -v ~/mysql/master/master.cnf:/etc/mysql/mysql.conf.d/master.cnf mysql:5.7 |
主库
添加复制账号
1 | $ docker exec -it mysql_master bash |
查看binlog位置
1 | mysql> SHOW MASTER STATUS; |
从库
配置同步信息
1 | $ docker exec -it mysql_slave bash |
开启同步
1 | mysql> START SLAVE; |
验证
1 | $ docker exec mysql_slave mysql -uroot -p123456 -e "SHOW DATABASES" |
All articles in this blog are licensed under CC BY-NC-SA 4.0 unless stating additionally.