mysql主从,一方发生错误,恢复方式

今天收到客服反馈,有用户登录失败,提示账户不存在,进入mycat里查询发现确实查不出数据,于是进入物理库分别查询,发现俩个物理库数据不同步,检查主从配置发现错误,如下:
mysql> show slave status\G;
Slave_IO_State: Waiting for master to send event
Master_Host: xx.xxx.xx.xx
Master_User: root
Master_Port: 3306
Connect_Retry: 60
Master_Log_File: mysql-bin.000004
Read_Master_Log_Pos: 273639293
Relay_Log_File: iZbp1cbpdn4wsuej4fhbfcZ-relay-bin.000002
Relay_Log_Pos: 2017959
Relay_Master_Log_File: mysql-bin.000004
Slave_IO_Running: Yes
Slave_SQL_Running: No
Replicate_Do_DB:textdbnew
Replicate_Ignore_DB:
Replicate_Do_Table:
Replicate_Ignore_Table:
Replicate_Wild_Do_Table:
Replicate_Wild_Ignore_Table:
Last_Errno: 1594
Last_Error: Relay log read failure: Could not parse relay log event entry. The possible reasons are: the master’s binary log is corrupted (you can check this by running ‘mysqlbinlog’ on the binary log), the slave’s relay log is corrupted (you can check this by running ‘mysqlbinlog’ on the relay log), a network problem, or a bug in the master’s or slave’s MySQL code. If you want to check the master’s binary log or slave’s relay log, you will be able to know their names by issuing ‘SHOW SLAVE STATUS’ on this slave.
Skip_Counter: 0
Exec_Master_Log_Pos: 94945936
Relay_Log_Space: 111997714
Until_Condition: None
Until_Log_File:
Until_Log_Pos: 0
Master_SSL_Allowed: No
Master_SSL_CA_File:
Master_SSL_CA_Path:
Master_SSL_Cert:
Master_SSL_Cipher:
Master_SSL_Key:
Seconds_Behind_Master: NULL
Master_SSL_Verify_Server_Cert: No
Last_IO_Errno: 0
Last_IO_Error:
Last_SQL_Errno: 1594
Last_SQL_Error: Relay log read failure: Could not parse relay log event entry. The possible reasons are: the master’s binary log is corrupted (you can check this by running ‘mysqlbinlog’ on the binary log), the slave’s relay log is corrupted (you can check this by running ‘mysqlbinlog’ on the relay log), a network problem, or a bug in the master’s or slave’s MySQL code. If you want to check the master’s binary log or slave’s relay log, you will be able to know their names by issuing ‘SHOW SLAVE STATUS’ on this slave.
Replicate_Ignore_Server_Ids:
Master_Server_Id: 104
Master_UUID: c81b1259-82ac-11e9-8bbb-00163e024c1e
Master_Info_File: /var/lib/mysql/master.info
SQL_Delay: 0
SQL_Remaining_Delay: NULL
Slave_SQL_Running_State:
Master_Retry_Count: 86400
Master_Bind:
Last_IO_Error_Timestamp:
Last_SQL_Error_Timestamp: 210423 11:28:53
Master_SSL_Crl:
Master_SSL_Crlpath:
Retrieved_Gtid_Set:
Executed_Gtid_Set:
Auto_Position: 0
Replicate_Rewrite_DB:
Channel_Name:
Master_TLS_Version:

解决方法,重新设置主从进程解决:
mysql> stop slave;
Query OK, 0 rows affected (0.02 sec)

mysql> reset slave;
Query OK, 0 rows affected (0.57 sec)

mysql> change master to master_host=‘xxx.xxx.xxx.xx’,
-> master_user=‘replicat’,
-> master_password=‘passw’,
-> master_log_file=‘mysql-bin.000004’,
-> master_log_pos=94945936;
Query OK, 0 rows affected, 2 warnings (0.07 sec)

mysql> start slave;
Query OK, 0 rows affected (0.03 sec)

注意点:重新设置主机的日志同步位置是以出错日志里的position开始, Exec_Master_Log_Pos: 94945936,还有日志文件也是:Relay_Master_Log_File: mysql-bin.000004。

如果数据量比较小,用这种方式可以,如果数据量大,且主从机在外网,建议采取如下方式:
注意先停止数据库访问,以免出现数据不同步
1.停止主从配置
stop slave;
reset slave;
2.拷贝主库数据到从库,表结构和数据一起导出
mysqldump -u root --default-character-set=gbk -p****** databasename > /home/eeet/bak.sql
3.进入从库的mysql
mysql> source bak.sql
导入数据到从库,这样比慢慢同步日志效率高很多
4.重新配置主从,搞定
主从配置不会的可以看前面的博客 https://blog.csdn.net/qq_33337927/article/details/104680912

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值