mysql主从复制(同步阿里云的RDS至自建数据库)

从库同步阿里云的RDS

阿里云默认开启了binglog,所以我们无需对主库进行配置

查询主库的server_id,从库配置不要重复就行

show variables like '%server_id%';

编辑从库的my.cnf文件

在文件中增加如下配置

server-id = 123456789 //服务 ID,主从实例 server-id 需不同。

log_bin = /var/log/mysql/mysql-bin.log

expire_logs_days = 10;

max_binlog_size = 100M

replicate-do-db = exampledb //需要同步的数据库

replicate-ignore-db = mysql //不需要同步的数据库

replicate-ignore-db = information_schema //不需要同步的数据库

replicate-ignore-db = performance_schema //不需要同步的数据库

GTID

gtid_mode=on

enforce_gtid_consistency=on

binlog_format=row //设置 binlog 为 row

log-slave-updates=1

设置同步选项

change master to master_host='rm-xxx.mysql.rds.aliyuncs.com', master_user='xxx', master_password='xxxx', master_port=3306, master_log_file='mysql-bin.000637', master_log_pos= 6433378, master_connect_retry=30;

其中的master_log_file和master_log_file通过在master上执行show master status;获得

但是需要注意如果主库数据有变更,这两个值可能会一直有变动,可以先执行如下命令锁表

锁表

flush tables with read lock;

解锁

unlock tables

启动从实例

start slave;

检查同步结果

show slave status\G

查看系统返回信息中 Slave_IO_Running 和 Slave_SQL_Running 的状态是否为 Yes,如下所示。

参考

https://developer.aliyun.com/article/66087

相关推荐
Elastic 中国社区官方博客10 小时前
搜索倍增器:推动收入、生产力和 AI 实现规模化
大数据·数据库·人工智能·elasticsearch·搜索引擎·ai·全文检索
东风破_10 小时前
从输入 juejin.cn 到看到页面:DNS、Nginx、服务器集群与 CDN 到底在做什么?
后端·mysql
小成很成10 小时前
mysql 8.0.21 升级 mysql 8.0.45(经过生产环境验证)
android·mysql·adb
东风破_11 小时前
从 0 设计一个博客数据库:用户、头像与文章表应该怎么建?
后端·mysql
保定公民12 小时前
达梦数据库存储过程中的数组类型详解:基础数组与记录数组的差异化应用
数据库·达梦·存储过程·达梦数据库·dm8·dm
梦Arrebol12 小时前
Redis 内容及相关实验
数据库·redis
大模型码小白12 小时前
Spring AI Tool 实现自然语言操作 MySQL 数据库详解
服务器·开发语言·数据库·人工智能·python·mysql·spring
云计算DevOps-韩老师14 小时前
【MySQL运维DBA】【SQL基础系列002篇】
运维·mysql·dba
DBA大董14 小时前
TDengine3.0 DBA常用的运维命令和SQL2
运维·数据库·时序数据库·dba·tdengine