Error
Error Code:
1778
MariaDB Error 1778: Implicit Commit with GTID_NEXT
Description
This error occurs when you attempt to execute a statement that triggers an implicit commit (such as DDL or DCL) while an explicit transaction is active and the `@@SESSION.GTID_NEXT` variable is not set to `AUTOMATIC`. MariaDB prevents this to maintain GTID consistency and replication integrity, as implicitly committed statements with a manually set `GTID_NEXT` can lead to an incorrect GTID sequence.
Error Message
Cannot execute statements with implicit commit inside a transaction when @@SESSION.GTID_NEXT != AUTOMATIC.
Known Causes
3 known causesDDL Statement in Transaction with Manual GTID_NEXT
Executing data definition language (DDL) statements like `CREATE TABLE`, `ALTER TABLE`, or `DROP TABLE` within an active transaction when `@@SESSION.GTID_NEXT` is manually assigned.
DCL Statement in Transaction with Manual GTID_NEXT
Running data control language (DCL) statements such as `GRANT` or `REVOKE` permissions inside an explicit transaction while `@@SESSION.GTID_NEXT` is set to a specific GTID value.
Other Implicit Commit Statements
Attempting to execute other statements that cause an implicit commit (e.g., `TRUNCATE TABLE`, `LOCK TABLES`) within an active transaction when `@@SESSION.GTID_NEXT` is not `AUTOMATIC`.
Solutions
3 solutions available1. Explicitly Set GTID_NEXT to AUTOMATIC easy
Ensure GTID_NEXT is set to AUTOMATIC before starting transactions that might implicitly commit.
1
Before executing statements that might cause an implicit commit within a transaction (like DDL statements or certain `SET` statements), explicitly set `GTID_NEXT` to `AUTOMATIC`.
SET SESSION GTID_NEXT = AUTOMATIC;
2
Then, execute your transaction. MariaDB will automatically advance `GTID_NEXT` after the transaction completes.
-- Your transactional SQL statements here --
2. Avoid Implicit Commits within Transactions medium
Identify and rewrite code that performs implicit commits inside transactions.
1
Review your application code and SQL scripts. Look for statements that implicitly commit transactions. Common culprits include DDL statements (e.g., `CREATE TABLE`, `ALTER TABLE`, `DROP TABLE`), `LOCK TABLES`, `UNLOCK TABLES`, and certain `SET` statements (e.g., `SET SESSION TRANSACTION ISOLATION LEVEL ...`).
--- Example of problematic code ---
START TRANSACTION;
CREATE TABLE my_new_table (id INT);
-- Other DML statements --
COMMIT;
2
Rewrite your code to avoid executing these implicit commit statements within an active transaction. If a DDL statement is necessary, consider performing it outside of a transaction or using `SET SESSION GTID_NEXT = AUTOMATIC;` before it.
--- Example of rewritten code ---
-- Perform DDL outside transaction or with GTID_NEXT set --
SET SESSION GTID_NEXT = AUTOMATIC;
CREATE TABLE my_new_table (id INT);
SET SESSION GTID_NEXT = AUTOMATIC; -- Reset for subsequent operations if needed
START TRANSACTION;
-- Other DML statements --
COMMIT;
3. Configure Server to Allow Implicit Commits (Use with Caution) advanced
Temporarily allow implicit commits by disabling strict transaction control.
1
Modify the MariaDB server configuration file (e.g., `my.cnf` or `my.ini`). Add or modify the `gtid_domain_id` and `gtid_auto_position` settings, and potentially `enforce_gtid_consistency`.
[mysqld]
gtid_domain_id = 1
gtid_auto_position = 1
enforce_gtid_consistency = OFF
2
Restart the MariaDB server for the changes to take effect.
sudo systemctl restart mariadb
3
Understand the implications. Setting `enforce_gtid_consistency = OFF` can lead to inconsistencies in replication if not managed carefully and should generally be avoided in production environments unless you fully understand the risks. This is often a temporary measure for debugging or specific migration scenarios.
--- Important Note ---
This is a server-wide setting and affects all connections. It weakens GTID consistency guarantees.