1228
MySQLERRORCriticalSyntax / VariablesHIGH confidence

Only constant expressions allowed with SET

Production Risk

Low — syntax error; no data affected.

What this means

ER_SET_CONSTANTS_ONLY (1228, SQLSTATE HY000) is raised when a SET statement for a system variable uses a non-constant expression, which is not permitted.

Why it happens
  1. 1Using a subquery or function result in SET for a system variable
  2. 2Attempting to set a variable to a computed value that MySQL cannot evaluate at parse time
How to reproduce
trigger — this will error
trigger — this will error
SET GLOBAL max_connections = (SELECT value FROM config WHERE name='max_conn');  -- ERROR 1228

expected output

ERROR 1228 (HY000): Variable 'max_connections' can only be set to a constant

Fix

Compute the value first and then assign

Compute the value first and then assign
-- In application code:
-- val = SELECT value FROM config WHERE name='max_conn'
-- SET GLOBAL max_connections = <val>;

-- Or in a stored procedure:
SET @val = (SELECT value FROM config WHERE name='max_conn');
SET GLOBAL max_connections = @val;

Why this works

Store the computed value in a user variable first, then assign it to the system variable.

Sources
Official documentation ↗

MySQL 8.0 — 1228 ER_SET_CONSTANTS_ONLY

Content generated with AI assistance and reviewed for accuracy. Found an error? hello@errcodes.dev

← All MySQL errors