【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資料庫
- oninit -vy 出錯: Fatal error in shared memory creation 以及 shared memory already existsError
- vagrant up 啟動報錯 Stderr: VBoxManage.exe: error: A NAT rule of this name already existsError
- 【MySQL】5.6.x InnoDB Error Table mysql.innodb_table_stats not foundMySqlError
- Mysql故障處理2則MySql
- MySQL核心月報2014.10-MySQL· 捉蟲動態·binlog重放失敗MySql
- 奇怪報錯資訊“db already exists with different case already have”解決方法
- [ERROR] Can't open the mysql.plugin tableErrorMySqlPlugin
- create table if not exists Waiting for table metadata lockAI
- MYSQL ERROR 1146 Table doesnt exist 解析MySqlError
- MySQL報錯Table 'plugin' is read only [ERROR] Can't open the mysql.plugin table.MySqlPluginError
- dataguard故障處理一則
- git使用報錯fatal: remote origin already exists.GitREM
- Swap file "/etc/sysconfig/.iptables.swp" already exists!
- 刪除編輯檔案警告Swap file “…” already exists!
- linux——學習1the home directory already exists.Linux
- 解析MYSQL BINLOG 二進位制格式(4)--TABLE_MAP_EVENTMySql
- Kettle Table Exists控制元件優化控制元件優化
- 【MySQL】NOT EXISTS優化的一個案例MySql優化
- EWM error 'Delivery is already fully invoiced'Error
- 故障分析 | MySQL 異地從庫複製延遲案例一則MySql
- PRCS-1007 : Server pool racdb already existsServer
- 【MySQL】一、如何快速執行 binlogMySql
- MySQL之in與existsMySql
- beego報錯 table name: `xxx` not existsGo
- Query to Check SP/Table/Trigger Exists in Database or notDatabase
- IN&EXISTS與NOT IN&NOT EXISTS 的優化原則的討論優化
- GitHub 託管程式碼的部分 fatal: remote origin already existsGithubREM
- android/libs/libammsdk.jar" already exists! 解決方法AndroidJAR
- SNMP TABLE ERROR : Requested table is empty or does not existError
- TSM故障問題解決一則
- 解決儲存硬碟故障一則硬碟
- "OPatch failed with error code 73"故障一例AIError
- MySQL:Redo & binlogMySql
- mysql binlog管理MySql
- mysql binlog 刪除master- binlogMySqlAST
- MySQL DROP TABLE刪除表報錯'ERROR 1051 (42S02): Unknown table'MySqlError