云服务器docker搭建mysql一主一从自动复制【reggie_take_out】

https://blog.csdn.net/weixin_52938172/article/details/123929866
https://www.cnblogs.com/yppah/p/15817560.html

docker安装两个mysql

image
image
image

docker run \
--name mysql-master1 \
-e MYSQL_ROOT_PASSWORD=root \
-p 3304:3306 \
-v /tmp/mysql-master1/log:/var/log/mysql \
-v /tmp/mysql-master1/conf/:/var/etc/mysql \
-v /tmp/mysql-master1/data:/var/lib/mysql \
-d mysql:5.7.25

mysql-master1配置

docker run \
--name mysql-master1 \
-e MYSQL_ROOT_PASSWORD=root \
-p 3304:3306 \
-v /tmp/mysql-master1/log:/var/log/mysql \
-v /tmp/mysql-master1/conf/:/var/etc/mysql \
-v /tmp/mysql-master1/data:/var/lib/mysql \
-d mysql:5.7.25

image
image

image

mysql-slave1配置

docker run \
--name mysql-slave1 \
-e MYSQL_ROOT_PASSWORD=root \
-p 3305:3306 \
-v /tmp/mysql-slave1/log:/var/log/mysql \
-v /tmp/mysql-slave1/conf/:/var/etc/mysql \
-v /tmp/mysql-slave1/data:/var/lib/mysql \
-d mysql:5.7.25

image
image
image

远程连接

image

image
image

image

创建主节点用户,配置从节点连接

主节点

GRANT REPLICATION SLAVE ON *.* to 'xiaoming'@'%' identified by 'Root@123456';

image
遇到了与https://www.cnblogs.com/yppah/p/17061431.html相同的问题,参考https://blog.csdn.net/miachen520/article/details/122390084解决
image
image
重新修改各自挂载的配置文件并docker重启服务
image
image
image


SELECT @@sql_mode;

SET sql_mode=(SELECT REPLACE(@@sql_mode,'ONLY_FULL_GROUP_BY',''));

SELECT @@sql_mode;

image
image
image


image

show master status;

image
日志保存文件没配置好??
http://www.vsbclub.com/info/1024/1673.htm
image
原来是配置没生效

为解决、待解决

从节点

change master to master_host='主节点ip地址',
master_user='xiaoming',
master_password='Root@123456',
master_log_file='二进制日志文件名称',
master_log_pos=主节点二进制日志文件的position

测试

自动复制,同步数据

posted @ 2023-01-19 14:37  yub4by  阅读(9)  评论(0编辑  收藏  举报