Install Docker
- 主从配置
-
进入Master库容器
docker exec -it master-mariadb-service /bin/bash
-
打开另一个终端进入Slave容器
docker exec -it slave-mariadb-service /bin/bash
-
进入Master
/usr/bin/mysql -uroot -p
密码是root -
授权
GRANT REPLICATION SLAVE ON *.* TO 'slaveUser'@'10.5.0.6' IDENTIFIED BY '123456';
IP 参数代表从容器的ip -
flush privileges;
-
show master status;
File | Position | Binlog_Do_DB| Binlog_Ignore_DB master-bin.000005 | 635 |
-
进入Slave
/usr/bin/mysql -uroot -p
密码是root -
连接Master
change master to master_host='10.5.0.5', master_user='slaveUser', master_password='123456', master_log_file='master-bin.000005', //例子,自己根据自己系统显示修改 master_log_pos=635; //例子,自己根据自己系统显示修改
-
启动Slave
start slave;
-
查看是否开启
show slave status\G;
Slave_IO_Running: Yes //这两个为yes开启成功 Slave_SQL_Running: Yes //这两个为yes开启成功
-
测试
-
在Master中操作
create database test; CREATE TABLE `admin` ( `id` int(11) NOT NULL AUTO_INCREMENT, `name` varchar DEFAULT NULL COMMENT 'name', PRIMARY KEY (`id`)); insert into admin values('1','name');
-
-