【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中麼?
〇 復現:
-
[17:52:45] root@localhost [a]> FLUSH LOGS;
-
Query OK, 0 rows affected (0.01 sec)
-
-
[17:52:47] root@localhost [a]> SHOW BINLOG EVENTS IN 'mysql55-bin.000006';
-
+--------------------+-----+-------------+-----------+-------------+---------------------------------------+
-
| Log_name | Pos | Event_type | Server_id | End_log_pos | Info |
-
+--------------------+-----+-------------+-----------+-------------+---------------------------------------+
-
| mysql55-bin.000006 | 4 | Format_desc | 55 | 107 | Server ver: 5.5.57-log, Binlog ver: 4 |
-
+--------------------+-----+-------------+-----------+-------------+---------------------------------------+
-
1 row in set (0.00 sec)
-
-
[17:53:13] root@localhost [a]> CREATE TABLE t(id int);
-
Query OK, 0 rows affected (0.01 sec)
-
-
[17:53:18] root@localhost [a]> CREATE VIEW v_t AS SELECT * from t;
-
Query OK, 0 rows affected (0.00 sec)
-
-
[17:53:21] root@localhost [a]> CREATE VIEW v_t AS SELECT * from t;
- ERROR 1050 (42S01): Table 'v_t' already exists
此時,再次檢查binlog:
-
[17:53:24] root@localhost [a]> SHOW BINLOG EVENTS IN 'mysql55-bin.000006'\G
-
*************************** 1. row ***************************
-
Log_name: mysql55-bin.000006
-
Pos: 4
-
Event_type: Format_desc
-
Server_id: 55
-
End_log_pos: 107
-
Info: Server ver: 5.5.57-log, Binlog ver: 4
-
*************************** 2. row ***************************
-
Log_name: mysql55-bin.000006
-
Pos: 107
-
Event_type: Query
-
Server_id: 55
-
End_log_pos: 189
-
Info: use `a`; CREATE TABLE t(id int)
-
*************************** 3. row ***************************
-
Log_name: mysql55-bin.000006
-
Pos: 189
-
Event_type: Query
-
Server_id: 55
-
End_log_pos: 369
-
Info: use `a`; CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v_t` AS SELECT * from t
-
*************************** 4. row ***************************
-
Log_name: mysql55-bin.000006
-
Pos: 369
-
Event_type: Query
-
Server_id: 55
-
End_log_pos: 549
-
Info: use `a`; CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v_t` AS SELECT * from t
- 4 rows in set (0.00 sec)
可以發現,第二次執行CREATE VIEW,即便在mysql client執行時報錯,也被記錄到binlog中。
自然,在透過mysqlbinlog重放binlog時,也會報錯。
但在複製結構中,從例項不會重放該events,故從庫不會報錯。
重新透過mysqlbinlog解析日誌得到:
-
# at 107
-
#180206 17:53:18 server id 55 end_log_pos 189 Query thread_id=13 exec_time=0 error_code=0
-
use `a`/*!*/;
-
SET TIMESTAMP=1517910798/*!*/;
-
SET @@session.pseudo_thread_id=13/*!*/;
-
SET @@session.foreign_key_checks=1, @@session.sql_auto_is_null=0, @@session.unique_checks=1, @@session.autocommit=1/*!*/;
-
SET @@session.sql_mode=0/*!*/;
-
SET @@session.auto_increment_increment=1, @@session.auto_increment_offset=1/*!*/;
-
/*!\C utf8 *//*!*/;
-
SET @@session.character_set_client=33,@@session.collation_connection=33,@@session.collation_server=8/*!*/;
-
SET @@session.lc_time_names=0/*!*/;
-
SET @@session.collation_database=DEFAULT/*!*/;
-
CREATE TABLE t(id int)
-
/*!*/;
-
# at 189
-
#180206 17:53:21 server id 55 end_log_pos 369 Query thread_id=13 exec_time=0 error_code=0
-
SET TIMESTAMP=1517910801/*!*/;
-
CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v_t` AS SELECT * from t
-
/*!*/;
-
# at 369
- #180206 17:53:22 server id 55 end_log_pos 549 Query thread_id=13 exec_time=0 error_code=1050
-
SET TIMESTAMP=1517910802/*!*/;
-
CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v_t` AS SELECT * from t
- /*!*/;
至於為何從庫不報錯,大概是因為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增量恢復資料時,可能需要特殊處理。
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/29734436/viewspace-2151286/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- MySQL 5.6執行DDL報錯ERROR 1050 (42S01): Table 'sms/#sql-ib752' already existMySqlError
- django資料庫同步時報錯“Table 'XXX' already exists”Django資料庫
- vagrant up 啟動報錯 Stderr: VBoxManage.exe: error: A NAT rule of this name already existsError
- Swap file "/etc/sysconfig/.iptables.swp" already exists!
- 奇怪報錯資訊“db already exists with different case already have”解決方法
- git使用報錯fatal: remote origin already exists.GitREM
- MySQL報錯Table 'plugin' is read only [ERROR] Can't open the mysql.plugin table.MySqlPluginError
- beego報錯 table name: `xxx` not existsGo
- GitHub 託管程式碼的部分 fatal: remote origin already existsGithubREM
- VS error LNK2005:**already defined in **.objErrorOBJ
- 【MySQL】NOT EXISTS優化的一個案例MySql優化
- 【MySQL】一、如何快速執行 binlogMySql
- 故障分析 | MySQL 異地從庫複製延遲案例一則MySql
- MySQL:Redo & binlogMySql
- Mysql的binlog原理MySql
- MySQL Binlog 介紹MySql
- MySQL系列:binlog日誌詳解(引數、操作、GTID、最佳化、故障演練)MySql
- mysql 關於exists 和in分析MySql
- Mysql的redolog和binlogMySql
- MySQL 的日誌:binlogMySql
- mysql8.0插入慢之sync_binlog(一)MySql
- bind (ERROR 502): bind(0.0.0.0:8811) failed. Error: Address already in use [98] (埠被佔用)ErrorAI
- [20221227]a mutating table error without a trigger!.txtError
- ERROR 1114 (HY000) The table '' is fullError
- Mysql-binlog日誌-TMySql
- 教你MySQL Binlog實用攻略MySql
- EXISTS、IN、NOT EXISTS、NOT IN(zt)
- MySQL資料庫binlog解析神器-binlog2sql應用MySql資料庫
- Centos7系統建立使用者時出現“useradd: user ‘xxxx‘ already exists”錯誤CentOS
- MySql Binlog 說明 & Canal 整合MySql的更新異常說明 & MySql Binlog 常用命令彙總MySql
- MySQL:Analyze table導致'waiting for table flush'MySqlAI
- TiDB binlog故障處理之drainer週期性罷工TiDBAI
- MySQL table into a golang strucMySqlGolang
- MySQL8.0 binlog_row_metadataMySql
- Mysql資料庫監聽binlogMySql資料庫
- MySQL Binlog 解析工具 Maxwell 詳解MySql
- MySQL binlog和redo的組提交MySql
- MySQL中binlog cache使用流程解惑MySql
- 解決docker: Error response from daemon故障DockerError