国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 數據庫 > MySQL > 正文

MySQL主從同步報錯故障處置記錄

2024-07-24 12:35:58
字體:
來源:轉載
供稿:網友
  在發生故障切換后,經常遇到的問題就是同步報錯,下面是最近收集的報錯信息。
 
  記錄刪除失敗
  在master上刪除一條記錄,而slave上找不到
 
  Last_SQL_Error: Could not execute Delete_rows event on table hcy.t1;
  Can't find record in 't1',
  Error_code: 1032; handler error HA_ERR_KEY_NOT_FOUND;
  the event's master log mysql-bin.000006, end_log_pos 254
 
  解決方法:master要刪除一條記錄,而slave上找不到報錯,這種情況主都已經刪除了,那么從機可以直接跳過。
 
  stop slave;
  set global sql_slave_skip_counter=1;
  start slave;
  如果這種情況很多,需要針對這種錯誤專門寫相關腳本。
 
  主鍵重復
  在slave已經有該記錄,又在master上插入了同一條記錄。
 
  Last_SQL_Error: Could not execute Write_rows event on table hcy.t1;
  Duplicate entry '2' for key 'PRIMARY',
  Error_code: 1062;
  handler error HA_ERR_FOUND_DUPP_KEY; the event's master log mysql-bin.000006, end_log_pos 924
  解決方法:
 
  在slave上用desc hcy.t1; 先看下表結構:
 
  mysql> desc hcy.t1;
  +-------+---------+------+-----+---------+-------+
  | Field | Type    | Null | Key | Default | Extra |
  +-------+---------+------+-----+---------+-------+
  | id    | int(11) | NO   | PRI | 0       |       |
  | name  | char(4) | YES  |     | NULL    |       |
  +-------+---------+------+-----+---------+-------+
  刪除重復的主鍵
 
  mysql> delete from t1 where id=2;
  Query OK, 1 row affected (0.00 sec)
 
  mysql> start slave;
  Query OK, 0 rows affected (0.00 sec)
 
  mysql> show slave status/G;
  ……
  Slave_IO_Running: Yes
  Slave_SQL_Running: Yes
  ……
  mysql> select * from t1 where id=2;
  在master上和slave上再分別確認一下。
 
  更新丟失
  在master上更新一條記錄,而slave上找不到,丟失了數據。
 
  Last_SQL_Error: Could not execute Update_rows event on table hcy.t1;
  Can't find record in 't1',
  Error_code: 1032;
  handler error HA_ERR_KEY_NOT_FOUND;
  the event's master log mysql-bin.000010, end_log_pos 794
  解決方法:
 
  在master上,用mysqlbinlog 分析下出錯的binlog日志在干什么。
 
  /usr/local/mysql/bin/mysqlbinlog --no-defaults -v -v --base64-output=DECODE-ROWS mysql-bin.000010 | grep -A '10' 794
 
  #120302 12:08:36 server id 22  end_log_pos 794  Update_rows: table id 33 flags: STMT_END_F
  ### UPDATE hcy.t1
  ### WHERE
  ###   @1=2 /* INT meta=0 nullable=0 is_null=0 */
  ###   @2='bbc' /* STRING(4) meta=65028 nullable=1 is_null=0 */
  ### SET
  ###   @1=2 /* INT meta=0 nullable=0 is_null=0 */
  ###   @2='BTV' /* STRING(4) meta=65028 nullable=1 is_null=0 */
  # at 794
  #120302 12:08:36 server id 22  end_log_pos 821  Xid = 60
  COMMIT/*!*/;
  DELIMITER ;
  # End of log file
  ROLLBACK /* added by mysqlbinlog */;
  /*!50003 SET COMPLETION_TYPE=@OLD_COMPLETION_TYPE*/;
  在slave上,查找下更新后的那條記錄,應該是不存在的。
 
  mysql> select * from t1 where id=2;
  Empty set (0.00 sec)
  然后再到master查看
 
  mysql> select * from t1 where id=2;
  +----+------+
  | id | name |
  +----+------+
  |  2 | BTV  |
  +----+------+
  1 row in set (0.00 sec)
  把丟失的數據在slave上填補,然后跳過報錯即可。
 
  1236錯誤, 二進制文件缺失
  誤刪二進制文件等各種原因,導致主庫mysql-bin.000012文件丟失,從庫同步失敗。

(編輯:武林網)

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 那曲县| 绥滨县| 故城县| 股票| 枣强县| 青海省| 潞城市| 广元市| 长治市| 麻城市| 庄河市| 当阳市| 武汉市| 遵义市| 东兰县| 莱阳市| 当涂县| 红桥区| 佛坪县| 临沧市| 山阳县| 贵定县| 木兰县| 泸州市| 托克逊县| 平和县| 定州市| 长岛县| 阳春市| 北宁市| 北辰区| 紫云| 元氏县| 江达县| 如皋市| 随州市| 博湖县| 安吉县| 马龙县| 连云港市| 景泰县|