1781 database runtime_error ai_generated true

ERROR 1781 (HY000): 当 @_MODE = ON 时,@_NEXT 不能设置为 UUID:NUMBER。

ERROR 1781 (HY000): @_NEXT cannot be set to UUID:NUMBER when @_MODE = ON.

ID: database/mysql-gtid-purge-failure

其他格式: JSON · Markdown 中文 · English
95%修复率
85%置信度
1证据数
2023-10-05首次发现

版本兼容性

版本状态引入弃用备注
MySQL 5.7 active
MySQL 8.0 active
MySQL 8.4 active

根因分析

在启用 GTID 模式时尝试手动将 gtid_next 设置为特定 GTID,这是不允许的,因为 GTID 由服务器自动生成。

English

Attempting to manually set gtid_next to a specific GTID while GTID mode is enabled, which is not allowed because GTIDs are automatically generated by the server.

generic

官方文档

https://dev.mysql.com/doc/refman/8.0/en/replication-options-gtids.html#option_mysqld_gtid-mode

解决方案

  1. 首先将 gtid_next 设置为 'AUTOMATIC':`SET @@SESSION.GTID_NEXT = 'AUTOMATIC';` 然后让服务器自动生成 GTID。如果需要注入特定 GTID(例如,用于复制恢复),只有在确保 GTID_MODE 为 OFF 或使用不同会话时,才使用 `SET GTID_NEXT = 'UUID:NUMBER'`。
  2. 如果需要跳过 GTID(例如,副本上发生重复键错误后),使用 `SET GTID_NEXT = 'CONSISTENCY';` 然后 `BEGIN; COMMIT;` 然后重置为 AUTOMATIC:`SET @@SESSION.GTID_NEXT = 'AUTOMATIC';`

无效尝试

常见但无效的做法:

  1. Set gtid_next to 'AUTOMATIC' before setting it to a specific value 90% 失败

    This is the default state; the error occurs because you're trying to set gtid_next to a specific UUID:NUMBER, which is only allowed in manual mode or when GTID_MODE is OFF

  2. Disable GTID mode globally with SET GLOBAL gtid_mode = OFF 70% 失败

    Changing gtid_mode requires a specific sequence (OFF -> OFF_PERMISSIVE -> ON_PERMISSIVE -> ON) and may break replication if GTIDs are in use

  3. Ignore the error and proceed with the transaction 100% 失败

    The transaction will fail to commit because gtid_next is in an invalid state