当前位置:网站首页>记一次 mysql 主从不同步问题排查
记一次 mysql 主从不同步问题排查
2022-06-11 12:05:00 【乌托邦为什么被占用了】
背景:主库用的阿里云RDS mysql5.7 备库则是服务器自建的mysql
原因:因主库RDS被锁定后一段时间,连接不可用,导致主从不同步
解决:
登录到从库查看
mysql -h host -uroot -p'password'
use database;
show slave status\G; -- 查看对应库的运行情况,发现Last_Error日志:
The slave I/O thread stops because a fatal error is encountered when it try to get the value of SERVER_ID variable from master. Error: The MySQL server is running with the --rds-deny-access option so it cannot execute this statement
查找资料,于是一顿操作猛如虎。。。。。
stop slave for channel 'trade'; --先将从库停止,因该实例还有很多其他数据库,所以for channel 指定具体某个库
CHANGE MASTER TO MASTER_HOST = 'host', MASTER_USER = 'user', MASTER_PASSWORD = 'password', MASTER_PORT = 3306, MASTER_LOG_FILE='mysql-bin.000315', MASTER_LOG_POS =505071 for channel 'talent_circle';
-- 其中MASTER_LOG_FILE 与 MASTER_LOG_POS 两个参数需要到master库通过show master status;查看binlog日志以及对应的postion 号
start slave for channel 'trade'; --启动从库
show slave status\G; 再次查看对应库的运行情况,没问题
运行了一段时间后,发现未能同步,查看状态还是有错误,原因在于间隔时间太长,同步某条数据时同步导致
只能通过更残暴的方法,停止从库,数据清除,重新将主库的数据导入至从库。主要步骤是,从主库导出sql文件,再解锁主库,停止从库,导入从库,启动从库。(若库或者表较大,建议先锁主库,停止主库写操作,因是凌晨三点操作,且库较小,所以就没进行锁库操作)
步骤一:
mysqldump -hhost(主库地址) -uuser -p'password' --master-data=2 --single-transaction --databases --add-drop-database trade > /opt/dump/bak_190909.sql
--master-data=2 表示在dump过程中记录主库的binlog和pos点,并在dump文件中注释掉这一行;
--databases 指定某个数据库;
--add-drop-database 每个数据库创建之前添加drop数据库语句;
--single-transaction 设置事务的隔离级别为可重复读
步骤二:
stop slave for channel 'trade'; 停止从库
步骤三:
mysql -h host -uuser -p'password' trade< /opt/dump/bak_190909.sql 导入到从库
步骤四:
start slave for channel 'trade'; 启动从库
show slave status\G; 查看从库状态
边栏推荐
- centos安装mysql5.7
- Adjust the array order so that odd numbers precede even numbers (C language)
- ELK - ElastAlert最大的坑
- 苹果MobileOne: 移动端仅需1ms的高性能骨干
- 阶乘后的零(C语言)
- Elk - hearthbeat implements service monitoring
- When I saw the sudden death of a 28 year old employee, I wanted to moisten
- Centos7.x下安装mysql8遇到的问题Couldn‘t open file /etc/pki/rpm-gpg/RPM-GPG-KEY-mysql-2022
- 2020-07 学习笔记整理
- Splunk 健康检查之关闭THP
猜你喜欢

When the security engineer finds a major vulnerability in the PS host, the CD can execute arbitrary code in the system

Wechat web developers, how to learn web development

读取geo表达矩阵

The role of Gerber file in PCB manufacturing

Splunk最佳实践之workload managment

Notes on topic brushing (XIV) -- binary tree: sequence traversal and DFS, BFS

ELK - X-Pack设置用户密码

CentOS installation mysql5.7

mysql 导入宝塔中数据库data为0000-00-00,enum为null出错

iframe 传值
随机推荐
JVM class loading process
Where is it safer to open an account for soda ash futures? How much capital is needed for a transaction?
刷题笔记(十三)--二叉树:前中后序遍历(复习)
【LeetCode】494. Objective and (2 wrong questions)
Live app source code, and the status bar and navigation bar are set to transparent status
JEST 单元测试说明 config.json
iframe 传值
(推荐)splunk 多少数量search head 才合适
[file upload vulnerability 06] server file content detection and bypass experiment + image horse production method (based on upload-labs-14 shooting range)
Using fast and slow pointer method to solve the problem of array (C language)
中国网络安全年会周鸿祎发言:360安全大脑构筑数据安全体系
Guice integrated properties configuration
线程五种状态(线程生命周期)
Centos7.x下安装mysql8遇到的问题Couldn‘t open file /etc/pki/rpm-gpg/RPM-GPG-KEY-mysql-2022
苹果MobileOne: 移动端仅需1ms的高性能骨干
ELK - Hearthbeat实现服务监控
Merge two ordered arrays (C language)
纯数据业务的机器打电话进来时回落到了2G/3G
軟件項目管理 7.1.項目進度基本概念
你管这破玩意儿叫 MQ?