failed executing transaction 'ANONYMOUS' at master

測試MySQL5.6 到MySQL5.7跨版本的多源複製功能,MySQL5.6中(Master)更新mysql.user表時,遇到如下錯誤:

Master1:
mysql> delete from mysql.user where user=’master1’;
Query OK, 1 row affected (0.00 sec)

Slave:
mysql>show slave status\G
Last_SQL_Errno: 1677
Last_SQL_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.000001,
end_log_pos 1318. See error log and/or performance_schema.replication_applier_status_by_worker table for more
details about this failure or others, if any.**

mysql> select * from performance_schema.replication_applier_status_by_worker where LAST_ERROR_NUMBER>0\G
***************** 1. row *****************
CHANNEL_NAME: master_1
WORKER_ID: 6
THREAD_ID: NULL
SERVICE_STATE: OFF
LAST_SEEN_TRANSACTION: ANONYMOUS
LAST_ERROR_NUMBER: 1677
LAST_ERROR_MESSAGE: Worker 6 failed executing transaction ‘ANONYMOUS’ at master log mysql-bin.000001, end_log_pos 1318; Column 1 of table ‘mysql.user’ cannot be converted from type ‘char(48(bytes))’ to type ‘char(96(bytes) utf8)’
LAST_ERROR_TIMESTAMP: 2017-09-14 11:54:05
1 row in set (0.00 sec)

對比MySQL5.6和MySQL5.7的mysql.user表結變化:
MySQL5.6
1.User char(16)
2. 有Password字段

MySQL5.7
1.User char(32)
2.去掉Password字段
3.增加了三個字段password_last_changed,password_lifetime,account_locked

由於表結構的變化,在基於row的複製模式下,Master(MySQL5.6)上更新mysql.user表無法同步到Slave(MySQL5.7)上.

解決這個問題比較簡單。
Master上(MySQL5.6)設置session級別的binlog_format 爲statement,再刪除user表中的用戶即可。
mysql> set session binlog_format=’STATEMENT’;
Query OK, 0 rows affected (0.00 sec)

mysql> delete from mysql.user where user=’master1’;

儘管官方是支持從低版本的Master到高版本的Slave這種架構,但還是推薦Master,Slave保持版本一致。
https://dev.mysql.com/doc/refman/5.7/en/replication-compatibility.html
MySQL supports replication from one release series to the next higher release series.
For example, you can replicate from a master running MySQL 5.5 to a slave running MySQL 5.6,
from a master running MySQL 5.6 to a slave running MySQL 5.7, and so on.

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章