暂无图片
暂无图片
暂无图片
暂无图片
暂无图片

MySQL 一主两从快速部署教程(基于 MySQL 8.0.28)

原创 代野(Tank) 2022-02-24
2688

MySQL 8.0.28
CentOS 7.6

主从架构的搭建过程相对简单,MySQL 配置文件中添加 server-id 及指定日志参数配置后,在实例中做几步操作即可完成。

需提前准备好 3 个 MySQL 实例,单机部署文档可以参考 CentOS7.6 安装部署 MySQL 8.0.28一文。

修改配置文件

—Master

# /etc/my.cnf server-id=1 log-bin=master-bin log-bin-index=master-bin.index

—Slave1

# /etc/my.cnf server-id=2 relay-log-index=slave-relay-bin.index relay-log=slave-relay-bin

—Slave2

# /etc/my.cnf server-id=3 relay-log-index=slave-relay-bin.index relay-log=slave-relay-bin

实例配置

—Master

CREATE USER 'slave1'@'192.168.56.104' IDENTIFIED BY 'Slave@2022'; GRANT REPLICATION SLAVE ON *.* TO 'slave1'@'192.168.56.104'; FLUSH PRIVILEGES; CREATE USER 'slave2'@'192.168.56.105' IDENTIFIED BY 'Slave@2022'; GRANT REPLICATION SLAVE ON *.* TO 'slave2'@'192.168.56.105'; FLUSH PRIVILEGES;
show master status\G; *************************** 1. row *************************** File: master-bin.000001 Position: 2089 Binlog_Do_DB: Binlog_Ignore_DB: Executed_Gtid_Set: 1 row in set (0.00 sec) ERROR: No query specified

—Slave1

change master to master_host='192.168.56.103',master_port=3306, master_user='slave1',master_password='Slave@2022',master_log_file='master-bin.000001',master_log_pos=2089; reset slave; start slave; show slave status\G; select * from performance_schema.replication_applier_status_by_worker\G mysql -uslave1 -pSlave@2022 -h192.168.56.103 -P3306

—Slave2

change master to master_host='192.168.56.103',master_port=3306, master_user='slave2',master_password='Slave@2022',master_log_file='master-bin.000001',master_log_pos=2089; reset slave; start slave; show slave status\G; select * from performance_schema.replication_applier_status_by_worker\G mysql -uslave2 -pSlave@2022 -h192.168.56.103 -P3306

至此,1 主 2 从的架构已部署完毕。

参考

[1] https://www.jianshu.com/p/79cea823ade8

[2] MySQL一主两从 - 沧澜猛兽 - 博客园 (cnblogs.com)

[3] mysql主从复制错误:A slave with the same server_uuid/server_id as this slave has connected to the master; - harara-小念 - 博客园 (cnblogs.com)

[4] mysql 主从复制 忽略错误_weixin_33981932的博客-CSDN博客


Tank

2022.1.19

最后修改时间:2022-02-27 00:09:52
「喜欢这篇文章,您的关注和赞赏是给作者最好的鼓励」
关注作者
【版权声明】本文为墨天轮用户原创内容,转载时必须标注文章的来源(墨天轮),文章链接,文章作者等基本信息,否则作者和墨天轮有权追究责任。如果您发现墨天轮中有涉嫌抄袭或者侵权的内容,欢迎发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。

评论