千家信息网

【MySQL】重放binlog故障一则 ERROR 1050 (42S01) : Table '' already exists

发表于:2026-11-01 作者:千家信息网编辑
千家信息网最后更新 2026年11月01日,〇 现象: 在通过binlog增量恢复数据时,报错1050。〇 版本: MySQL 5.5.x 及以下 ,低版本的MySQL 5.6.x (在5.6的高版本中测试,无法复现,疑似被修复)〇 原因: b
千家信息网最后更新 2026年11月01日【MySQL】重放binlog故障一则 ERROR 1050 (42S01) : Table '' already exists
〇 现象:
在通过binlog增量恢复数据时,报错1050。
〇 版本:
MySQL 5.5.x 及以下 ,低版本的MySQL 5.6.x (在5.6的高版本中测试,无法复现,疑似被修复)
〇 原因:
binlog记录了执行出错的DDL语句,此处,具体DDL是CREATE VIEW $view_name AS ...

有点奇怪,难道执行错误了的DDL也会被记录到binlog中么?

〇 复现:

  1. [17:52:45] root@localhost [a]> FLUSH LOGS;
  2. Query OK, 0 rows affected (0.01 sec)

  3. [17:52:47] root@localhost [a]> SHOW BINLOG EVENTS IN 'mysql55-bin.000006';
  4. +--------------------+-----+-------------+-----------+-------------+---------------------------------------+
  5. | Log_name | Pos | Event_type | Server_id | End_log_pos | Info |
  6. +--------------------+-----+-------------+-----------+-------------+---------------------------------------+
  7. | mysql55-bin.000006 | 4 | Format_desc | 55 | 107 | Server ver: 5.5.57-log, Binlog ver: 4 |
  8. +--------------------+-----+-------------+-----------+-------------+---------------------------------------+
  9. 1 row in set (0.00 sec)

  10. [17:53:13] root@localhost [a]> CREATE TABLE t(id int);
  11. Query OK, 0 rows affected (0.01 sec)

  12. [17:53:18] root@localhost [a]> CREATE VIEW v_t AS SELECT * from t;
  13. Query OK, 0 rows affected (0.00 sec)

  14. [17:53:21] root@localhost [a]> CREATE VIEW v_t AS SELECT * from t;
  15. ERROR 1050 (42S01): Table 'v_t' already exists

此时,再次检查binlog:
  1. [17:53:24] root@localhost [a]> SHOW BINLOG EVENTS IN 'mysql55-bin.000006'\G
  2. *************************** 1. row ***************************
  3. Log_name: mysql55-bin.000006
  4. Pos: 4
  5. Event_type: Format_desc
  6. Server_id: 55
  7. End_log_pos: 107
  8. Info: Server ver: 5.5.57-log, Binlog ver: 4
  9. *************************** 2. row ***************************
  10. Log_name: mysql55-bin.000006
  11. Pos: 107
  12. Event_type: Query
  13. Server_id: 55
  14. End_log_pos: 189
  15. Info: use `a`; CREATE TABLE t(id int)
  16. *************************** 3. row ***************************
  17. Log_name: mysql55-bin.000006
  18. Pos: 189
  19. Event_type: Query
  20. Server_id: 55
  21. End_log_pos: 369
  22. Info: use `a`; CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v_t` AS SELECT * from t
  23. *************************** 4. row ***************************
  24. Log_name: mysql55-bin.000006
  25. Pos: 369
  26. Event_type: Query
  27. Server_id: 55
  28. End_log_pos: 549
  29. Info: use `a`; CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v_t` AS SELECT * from t
  30. 4 rows in set (0.00 sec)

可以发现,第二次执行CREATE VIEW,即便在mysql client执行时报错,也被记录到binlog中。
自然,在通过mysqlbinlog重放binlog时,也会报错。

但在复制结构中,从实例不会重放该events,故从库不会报错。

重新通过mysqlbinlog解析日志得到:
  1. # at 107
  2. #180206 17:53:18 server id 55 end_log_pos 189 Query thread_id=13 exec_time=0 error_code=0
  3. use `a`/*!*/;
  4. SET TIMESTAMP=1517910798/*!*/;
  5. SET @@session.pseudo_thread_id=13/*!*/;
  6. SET @@session.foreign_key_checks=1, @@session.sql_auto_is_null=0, @@session.unique_checks=1, @@session.autocommit=1/*!*/;
  7. SET @@session.sql_mode=0/*!*/;
  8. SET @@session.auto_increment_increment=1, @@session.auto_increment_offset=1/*!*/;
  9. /*!\C utf8 *//*!*/;
  10. SET @@session.character_set_client=33,@@session.collation_connection=33,@@session.collation_server=8/*!*/;
  11. SET @@session.lc_time_names=0/*!*/;
  12. SET @@session.collation_database=DEFAULT/*!*/;
  13. CREATE TABLE t(id int)
  14. /*!*/;
  15. # at 189
  16. #180206 17:53:21 server id 55 end_log_pos 369 Query thread_id=13 exec_time=0 error_code=0
  17. SET TIMESTAMP=1517910801/*!*/;
  18. CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v_t` AS SELECT * from t
  19. /*!*/;
  20. # at 369
  21. #180206 17:53:22 server id 55 end_log_pos 549 Query thread_id=13 exec_time=0 error_code=1050
  22. SET TIMESTAMP=1517910802/*!*/;
  23. CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v_t` AS SELECT * from t
  24. /*!*/;
可以发现第二次报错的语句,虽然被记录到binlog中,但error_code标识为1050

至于为何从库不报错,大概是因为sql thread会特殊处理这种error_code,不会执行。
而mysqlbinlog mysql-binlog.00000x | mysql -u -p -S 重放binlog的方式会报错。--大概是因为mysql这个client工具没有做对mysqlbinlog解析出来的error_code的特殊处理吧。

暂时不知道是否为bug,但高版本的MySQL5.6.x已经修正了该问题,5.7也如此。

因此,在可能出现问题的版本,通过binlog增量恢复数据时,可能需要特殊处理。



版本 特殊 处理 增量 数据 语句 问题 会报 再次 原因 实例 工具 方式 日志 时报 标识 现象 结构 自然 错误 数据库的安全要保护哪些东西 数据库安全各自的含义是什么 生产安全数据库录入 数据库的安全性及管理 数据库安全策略包含哪些 海淀数据库安全审计系统 建立农村房屋安全信息数据库 易用的数据库客户端支持安全管理 连接数据库失败ssl安全错误 数据库的锁怎样保障安全 百单网互联网科技有限公司怎么样 河南云网互联网络科技有限公司 科技互联网产品 互联网科技官网 互联网科技未来 北京互联网科技有限公司 伴你行互联网科技有限公司 佰商互联网科技有限公司 互联网科技股有哪些 新华互联网科技校企合作 成都仁贤领冠互联网科技有限公司 汉立互联网科技有限公司联系电话 北京华百购互联网科技有限公司 翼展科技 首家互联网医院 广东工业互联网大赛深圳学泰科技 广州千川互联网科技有限公司 互联网相关科技技术 互联网科技包装股 国产互联网科技公司 版纳互联网科技选哪家 猪兼强互联网科技 安徽鑫晟辉互联网科技 互联网科技上市公司 居家互联网科技有限公司 广州慧亚互联网科技怎么样 互联网金融科技公司干啥的 湖南一路畅行互联网科技 九思连强互联网电子科技有限公司 昆明中奇联合互联网科技 知域互联网科技有限公司官网
0