{
  "id": "database/mysql-gtid-purge-failure",
  "signature": "ERROR 1781 (HY000): @_NEXT cannot be set to UUID:NUMBER when @_MODE = ON.",
  "signature_zh": "ERROR 1781 (HY000): 当 @_MODE = ON 时，@_NEXT 不能设置为 UUID:NUMBER。",
  "regex": "@@SESSION\\.GTID_NEXT cannot be set to.*when @@GLOBAL\\.GTID_MODE = ON",
  "domain": "database",
  "category": "runtime_error",
  "subcategory": null,
  "root_cause": "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.",
  "root_cause_type": "generic",
  "root_cause_zh": "在启用 GTID 模式时尝试手动将 gtid_next 设置为特定 GTID，这是不允许的，因为 GTID 由服务器自动生成。",
  "versions": [
    {
      "version": "MySQL 5.7",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "MySQL 8.0",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "MySQL 8.4",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "Set gtid_next to 'AUTOMATIC' before setting it to a specific value",
      "why_fails": "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",
      "fail_rate": 0.9,
      "condition": "",
      "sources": []
    },
    {
      "action": "Disable GTID mode globally with SET GLOBAL gtid_mode = OFF",
      "why_fails": "Changing gtid_mode requires a specific sequence (OFF -> OFF_PERMISSIVE -> ON_PERMISSIVE -> ON) and may break replication if GTIDs are in use",
      "fail_rate": 0.7,
      "condition": "",
      "sources": []
    },
    {
      "action": "Ignore the error and proceed with the transaction",
      "why_fails": "The transaction will fail to commit because gtid_next is in an invalid state",
      "fail_rate": 1.0,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "Set gtid_next to 'AUTOMATIC' first: `SET @@SESSION.GTID_NEXT = 'AUTOMATIC';` Then let the server generate the GTID automatically. If you need to inject a specific GTID (e.g., for replication recovery), use `SET GTID_NEXT = 'UUID:NUMBER'` only after ensuring GTID_MODE is OFF or using a different session.",
      "success_rate": 0.95,
      "how": "Set gtid_next to 'AUTOMATIC' first: `SET @@SESSION.GTID_NEXT = 'AUTOMATIC';` Then let the server generate the GTID automatically. If you need to inject a specific GTID (e.g., for replication recovery), use `SET GTID_NEXT = 'UUID:NUMBER'` only after ensuring GTID_MODE is OFF or using a different session.",
      "condition": "",
      "sources": []
    },
    {
      "action": "If you need to skip a GTID (e.g., after a duplicate key error on replica), use `SET GTID_NEXT = 'CONSISTENCY';` followed by `BEGIN; COMMIT;` and then reset to AUTOMATIC: `SET @@SESSION.GTID_NEXT = 'AUTOMATIC';`",
      "success_rate": 0.9,
      "how": "If you need to skip a GTID (e.g., after a duplicate key error on replica), use `SET GTID_NEXT = 'CONSISTENCY';` followed by `BEGIN; COMMIT;` and then reset to AUTOMATIC: `SET @@SESSION.GTID_NEXT = 'AUTOMATIC';`",
      "condition": "",
      "sources": []
    }
  ],
  "workarounds_zh": [
    "首先将 gtid_next 设置为 'AUTOMATIC'：`SET @@SESSION.GTID_NEXT = 'AUTOMATIC';` 然后让服务器自动生成 GTID。如果需要注入特定 GTID（例如，用于复制恢复），只有在确保 GTID_MODE 为 OFF 或使用不同会话时，才使用 `SET GTID_NEXT = 'UUID:NUMBER'`。",
    "如果需要跳过 GTID（例如，副本上发生重复键错误后），使用 `SET GTID_NEXT = 'CONSISTENCY';` 然后 `BEGIN; COMMIT;` 然后重置为 AUTOMATIC：`SET @@SESSION.GTID_NEXT = 'AUTOMATIC';`"
  ],
  "transition_graph": {
    "leads_to": [],
    "preceded_by": [],
    "frequently_confused_with": []
  },
  "official_doc_url": "https://dev.mysql.com/doc/refman/8.0/en/replication-options-gtids.html#option_mysqld_gtid-mode",
  "official_doc_section": null,
  "error_code": "1781",
  "verification_tier": "ai_generated",
  "confidence": 0.85,
  "fix_success_rate": 0.95,
  "resolvable": "true",
  "first_seen": "2023-10-05",
  "last_confirmed": "2024-06-01",
  "last_updated": "2024-06-01",
  "evidence_count": 1,
  "tags": [],
  "locale": "en",
  "aliases": []
}