1771
MariaDBERRORNotableStored ProceduresHIGH confidence
Variable cannot be set inside a stored procedure
Production Risk
Low — routine creation or execution fails.
What this means
A SET statement inside a stored procedure attempted to assign a value to a system variable that cannot be changed within a stored routine context.
Why it happens
- 1Attempting to set session-restricted or global-only variables inside a stored procedure.
- 2Setting GTID_NEXT or similar replication variables inside a routine.
How to reproduce
trigger — this will error
trigger — this will error
DELIMITER // CREATE PROCEDURE test_proc() BEGIN SET GTID_NEXT = 'AUTOMATIC'; -- not allowed in stored procedures END//
expected output
ERROR 1771 (HY000): Variable 'gtid_next' cannot be set this way.
Fix
Move the variable assignment outside the stored procedure
Move the variable assignment outside the stored procedure
SET GTID_NEXT = 'AUTOMATIC'; -- execute at session level, not inside a procedure
Why this works
Certain system variables can only be set at session or global scope, not within routines.
What not to do
✕
Sources
Official documentation ↗
MySQL 8.0 — 1771 ER_VARIABLE_NOT_SETTABLE_IN_SP
Content generated with AI assistance and reviewed for accuracy. Found an error? hello@errcodes.dev