1944
MySQLERRORNotableStored RoutinesHIGH confidence
Not allowed to set autocommit from a stored function or trigger
Production Risk
Low — function/trigger creation may succeed but execution fails.
What this means
SET autocommit cannot be executed inside a stored function or trigger. Autocommit state must not be altered within atomic execution contexts.
Why it happens
- 1SET autocommit = 0 or SET autocommit = 1 inside a stored function or trigger body.
How to reproduce
trigger — this will error
trigger — this will error
CREATE FUNCTION f() RETURNS INT DETERMINISTIC BEGIN SET autocommit = 0; RETURN 1; END;
expected output
ERROR 1944 (HY000): Not allowed to set autocommit from a stored function or trigger.
Fix
Set autocommit before calling the stored function
Set autocommit before calling the stored function
SET autocommit = 0; SELECT my_function();
Why this works
Control transaction boundaries at the session level, outside of stored functions and triggers.
What not to do
✕
Sources
Official documentation ↗
MySQL 8.0 — 1944 ER_SP_CANT_SET_AUTOCOMMIT
Content generated with AI assistance and reviewed for accuracy. Found an error? hello@errcodes.dev