zoukankan      html  css  js  c++  java
  • mysql-5.6.20主从同步错误之Error_code: 1062 Duplicate entry '1' for key 'PRIMARY', Error_code: 1062

    1.接到mysql主从不同步的报警,看日志

            Relay_Master_Log_File: mysql-bin.000119
                 Slave_IO_Running: Yes
                Slave_SQL_Running: No
                  Replicate_Do_DB: 
              Replicate_Ignore_DB: 
               Replicate_Do_Table: 
           Replicate_Ignore_Table: 
          Replicate_Wild_Do_Table: 
      Replicate_Wild_Ignore_Table: 
                       Last_Errno: 1062
                       Last_Error: Could not execute Write_rows event on table bbh_159.log_process; Duplicate entry '1' for key 'PRIMARY', Error_code: 1062; handler error HA_ERR_FOUND_DUPP_KEY; the event's master log mysql-bin.000119, end_log_pos 764433484

    2.查看错误码Last_Errno: 1062信息

    出现的可能原因:
    1.程序可能在slave上进行了写操作
    2.也可能是slave机器重起后,事务回滚造成的.

    3.定位原因:

    1.程序可能在slave上进行了写操作
    程序在修改代码逻辑时,误将数据写入从库了

    4.解决问题

    1.登陆从库:mysql -h127.0.0.1 -uroot -P3307 -pxxxx
    2.查看从库同步情况:mysql> show slave statusG;
    3.关闭从库
    4.修改my.cnf
        加入 slave-skip-errors = 1062  【slave-skip-errors为只读参数,不支持在线更改
    5.启动从库 6.验证同步情况

    6.问题总结

    1.从库只能做读操作,不能写操作。
    2.使用从库时,应创建只读普通用户,避免执行写操作。
    3.开启只读模式,配置文件加入read-only = 1 ,但还需创建只读普通用户,因为只读模式对超级用户没有限制。
  • 相关阅读:
    【纪中集训2019.3.19】原样输出
    【纪中集训2019.3.11】树上四次求和
    【纪中集训2019.3.11】Cubelia
    【纪中集训2019.3.14】小凯的疑惑
    leetcode 18 4Sum
    leetcode 17 Letter Combinations of a Phone Number
    leetcode 11 Container With Most Water
    leetcode 16 3Sum Closest
    leetcode 15 3Sum
    leetcode 14 Longest Common Prefix
  • 原文地址:https://www.cnblogs.com/chenjw-note/p/14049509.html
Copyright © 2011-2022 走看看