创建容器
- 主节点容器创建
1 | docker run --name mastermysql -d -p 3307:3306 -e MYSQL_ROOT_PASSWORD=123456 -v /usr/local/docker/mysql/master/data:/var/lib/mysql -v /usr/local/docker/mysql/master/conf/my.cnf:/etc/mysql/my.cnf mysql:5.7.19 |
- 主节点配置my.cnf
1 | [mysqld] |
- 从节点容器创建
1 | docker run --name slavemysql -d -p 3308:3306 -e MYSQL_ROOT_PASSWORD=123456 -v /usr/local/docker/mysql/slave/data:/var/lib/mysql -v /usr/local/docker/mysql/slave/conf/my.cnf:/etc/mysql/my.cnf mysql:5.7.19 |
- 从节点配置my.cnf
1 | [mysqld] |
进入容器
- 主:docker exec -it mastermysql bash
- 从:docker exec -it slavemysql bash
授权复制权限
- 创建用户
1 | create user 'slave'@'%' identified by '123456'; |
- 授权
1 | GRANT REPLICATION SLAVE, REPLICATION CLIENT ON *.* TO 'slave'@'%'; |
查询节点状态
1 | # 主: |
从节点配置主从连接
1 | stop slave; |
注:查询主容器ip
1 | docker inspect --format='{{.NetworkSettings.IPAddress}}' 容器名称|容器id |
创建只读用户
1 | create user 'reader'@'%' identified by '123456'; |
...
...
00:00
00:00
If you like this blog or find it useful for you, you are welcome to comment on it. You are also welcome to share this blog, so that more people can participate in it. If the images used in the blog infringe your copyright, please contact the author to delete them. Thank you !