MySQL5.7 多源複製其中的一個chaannel 報錯如下:
mysql> select * from performance_schema.replication_applier_status_by_worker where LAST_ERROR_NUMBER>0\G
*************************** 1. row ***************************
CHANNEL_NAME: master_5
WORKER_ID: 6
THREAD_ID: NULL
SERVICE_STATE: OFF
LAST_SEEN_TRANSACTION: ANONYMOUS
LAST_ERROR_NUMBER: 1146
LAST_ERROR_MESSAGE: Worker 6 failed executing transaction 'ANONYMOUS' at master log mysql_bin.000063, end_log_pos 799245561; Error executing row event: 'Table 'mysql_proxy.info' doesn't exist'
LAST_ERROR_TIMESTAMP: 2017-09-22 18:27:54
1 row in set (0.00 sec)
show slave status for channe ‘master_5' \G
Replicate_Wild_Ignore_Table: mysql.%,information_schema.%,performance_scheme.%,sys.%,percona.%
Last_Errno: 1146
Last_Error: Coordinator stopped because there were error(s) in the worker(s).
The most recent failure being: Worker 6 failed executing transaction 'ANONYMOUS' at master log mysql_bin.000063, end_log_pos 799245561. See error log and/or performance_schema.
replication_applier_status_by_worker table for more details about this failure or others, if any.
原來SLAVE沒有mysql_proxy 這個庫。
mysql> SELECT SCHEMA_NAME from information_schema.SCHEMATA where SCHEMA_NAME like 'mysql%';
+-------------+
| SCHEMA_NAME |
+-------------+
| mysql |
+-------------+
1 row in set (0.00 sec)
Master 上是有的
mysql> SELECT SCHEMA_NAME from information_schema.SCHEMATA where SCHEMA_NAME like 'mysql%';
+-------------+
| SCHEMA_NAME |
+-------------+
| mysql |
| mysql_proxy |
+-------------+
2 rows in set (0.00 sec)
Slave 上爲什麼沒有同步過來mysql_proxy 這個庫呢?
原來在備份數據庫的時候過濾掉了mysql相關的庫,所以導致mysql_proxy庫沒備份。
for database in `$mycmd -e "show databases;"|grep -Ev "Database|information_schema|performance_schema|test|mysql|percona"`
do
${DUMP_InnoDB} ${database} |gzip >> $BACKUPPATH/$BACKUPDATE/$BACKUPPORT/$(date +%w).sql.gz
解決:
由於只是一個schema中的一個配置表,記錄就幾條,更新也不頻繁。在master上導出後,直接在slave上恢復,跳過幾個錯誤就ok了。
如果涉及到的schema和記錄比較多,就需要重返工,新建立同步關係了。
如何避免上述問題呢:
如果能在master導出前和slave導入後對比一下schema的數量,或許會避免這個問題。
mysql> SELECT count(1) from information_schema.SCHEMATA where SCHEMA_NAME not in ('mysql','information_schema','performance_scheme','sys','percona');
+----------+
| count(1) |
+----------+
| 25 |
+----------+
還好是在測試中發現了這個腳本的問題,如果在線上發現這個問題,就是一個事故了。
另外,數據庫起名的時候,最好起一些與業務相關的名字 ,不要使用數據庫的關鍵字。