升級 5.6 後啟用 GTID (enforce_gtid_consistency=ON),執行跨引擎更新報錯:updates to non-transactional tables can only be done in either autocommitted statements or single-statement transactions, and never in the same statement as updates to transactional tables。
GTID 模式下,為保證主從一致性,**禁止在同一事務/語句中同時更新事務表與非事務表**。典型場景:業務表用 InnoDB,日誌/統計表用 MyISAM,一條存儲過程或多表 UPDATE 觸發限制。
Updates to tables using nontransactional storage engines such as MyISAM cannot be made in the same statement or transaction as updates to tables using transactional storage engines such as InnoDB.
ALTER TABLE tbl ENGINE=InnoDB;),徹底消除問題,同時獲得事務、行鎖、崩潰恢復優勢。SET GLOBAL enforce_gtid_consistency=OFF;(不推薦,失去 GTID 一致性保證,主從易漂移)。SELECT TABLE_NAME, ENGINE FROM information_schema.TABLES WHERE TABLE_SCHEMA='db' AND ENGINE='MyISAM'; 掃描非事務表。