当前位置:网站首页>记一次 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; 查看从库状态
边栏推荐
- Android 11+ 配置SqlServer2014+
- golang利用异或^交换两个变量以及加解密
- Splunk Bucket 背后的秘密
- C # set or verify the format of text field in PDF
- Memory mapping image of the grayloc module in the surfacefinder process
- Use of RadioButton in QT
- Iframe value transfer
- C# 设置或验证 PDF中的文本域格式
- 带你了解直接插入排序(C语言)
- CVPR 2022 | 文本引导的实体级别图像操作ManiTrans
猜你喜欢

Splunk 最佳实践-减轻captain 负担

SQLServer连接数据库(中文表)部分数据乱码问题解决
![[file upload vulnerability 06] server file content detection and bypass experiment + image horse production method (based on upload-labs-14 shooting range)](/img/30/79516390c2b2b50a224eaa84a0c1c9.jpg)
[file upload vulnerability 06] server file content detection and bypass experiment + image horse production method (based on upload-labs-14 shooting range)

Intermediate web development engineer, interview questions + Notes + project practice

数据如何在 Splunk 中老化?

Node connects to MySQL database and writes fuzzy query interface

Let you understand selection sorting (C language)

Splunk最佳实践之workload managment

Wechat web developers, how to learn web development

When the security engineer finds a major vulnerability in the PS host, the CD can execute arbitrary code in the system
随机推荐
[第二章 基因和染色体的关系]生物知识概括–高一生物
CVPR 2022 | 文本引导的实体级别图像操作ManiTrans
Elk - x-pack set user password
Splunk Bucket 背后的秘密
JS addition and multiplication error resolution number precision
Elk - elastalert largest pit
How does Sister Feng change to ice?
P2580 "so he started the wrong roll call"
Using fast and slow pointer method to solve the problem of array (C language)
JVM class loading process
近期使用nodejs pinyin包时遇到的问题
安全工程师发现PS主机重大漏洞 用光盘能在系统中执行任意代码
Splunk Bucket 背後的秘密
yapi安装
Golang uses XOR ^ to exchange two variables and encrypt / decrypt them
JS to realize the rotation chart (riding light). Pictures can be switched left and right. Moving the mouse will stop the rotation
Zhouhongyi's speech at the China Network Security Annual Conference: 360 secure brain builds a data security system
Memory mapping image of the grayloc module in the surfacefinder process
让你搞懂冒泡排序(C语言)
Solve the problem of swagger document interface 404