Common SQL Errors

MySQL Error 1621: ER_VARIABLE_IS_READONLY - How to Fix Read-Only Variable Assignment

Galaxy Team
August 7, 2025

<p>MySQL raises error 1621 when a SET statement tries to modify a system variable that is marked read-only.</p>

Sign up for the latest in common SQL errors from the Galaxy Team!
Welcome to the Galaxy, Guardian!
You'll be receiving a confirmation email

Follow us on twitter :)
Oops! Something went wrong while submitting the form.

What is MySQL error 1621 ER_VARIABLE_IS_READONLY?

<p>MySQL Error 1621 ER_VARIABLE_IS_READONLY occurs when a statement tries to change a read-only system variable. Remove the assignment or use SET PERSIST or an updateable alias to resolve the issue.</p>

Error Highlights

Typical Error Message

%s variable '%s' is read-only. Use SET %s to assign the

Error Type

Configuration Error

Language

MySQL

Symbol

ER_VARIABLE_IS_READONLY

Error Code

1621

SQL State

HY000

Explanation

Table of Contents

What does MySQL Error 1621 ER_VARIABLE_IS_READONLY mean?

The server returns ER_VARIABLE_IS_READONLY when a user issues SET or ALTER INSTANCE for a variable defined as read-only at the requested scope. MySQL blocks the change to protect internal consistency.

The message format is: %s variable '%s' is read-only. Use SET %s to assign the value. The placeholders show the scope, variable name, and valid clause.

When does this error appear?

The error is most common during session initialization scripts, configuration migrations, or automated deployments that include blanket SET GLOBAL statements. It also surfaces in stored procedures or ORM-generated SQL that manipulates server variables.

What Causes This Error?

Attempting to change variables like 'version', 'innodb_version', or 'hostname' will always fail because they are immutable while the server is running.

Misunderstanding between SESSION and GLOBAL scopes triggers the error when a variable is writable only at startup but not at runtime.

How to Fix MySQL Error 1621

First, identify the variable. Check the read_only column in performance_schema.system_variables or run SHOW VARIABLES LIKE 'name'.

If MySQL offers a writable companion variable or SET PERSIST support, switch to that method. Otherwise, remove the statement or place the value in my.cnf and restart.

Common Scenarios and Solutions

CICD pipelines often include SET GLOBAL statements for every parameter. Trim the list to exclude read-only entries.

Some ORMs enable ANSI mode by toggling sql_mode. Use SET SESSION sql_mode instead of SET GLOBAL when running as a non-admin user.

Best Practices to Avoid This Error

Verify variable mutability with SHOW VARIABLES or the INFORMATION_SCHEMA before issuing SET commands.

Store permanent configuration inside my.cnf and reserve runtime changes for documented dynamic variables only.

Related Errors and Solutions

Error 1238 variable does not exist - occurs when the name is misspelled. Correct the identifier.

Error 1229 variable is read-only when SUPER privilege is missing. Grant proper privileges or use SESSION scope.

Common Causes

Attempting to Modify Version Variables

Variables such as version and innodb_version are informational and cannot be changed at runtime.

Incorrect Scope Usage

Using SET GLOBAL on a parameter that is only dynamic at SESSION scope or vice-versa produces the read-only error.

Lack of Privileges

Without SUPER or SYSTEM_VARIABLES_ADMIN privileges, MySQL treats some dynamic variables as read-only to the caller.

Automation Scripts with Blanket SET

Scripts that iterate over parameter lists often include immutable variables that trigger the error during deployment.

Related Errors

MySQL Error 1229 variable_is_readonly

Raised when a variable is read-only due to insufficient privileges. Grant SYSTEM_VARIABLES_ADMIN to resolve.

MySQL Error 1238 ER_BAD_VARIB_NAME

Occurs when the variable name does not exist. Check spelling.

MySQL Error 1193 ER_UNKNOWN_SYSTEM_VARIABLE

Thrown when referencing a variable removed in the current server version. Review release notes.

FAQs

Can I force a read-only variable to change without restart?

No. Read-only variables are locked by design to ensure server stability. Only a restart with a new my.cnf value will take effect.

Does SET PERSIST work on read-only variables?

No. SET PERSIST only applies to variables marked dynamic. Attempting it on immutable variables still raises error 1621.

Which privileges are needed to change system variables?

For GLOBAL scope, the account must have SUPER or SYSTEM_VARIABLES_ADMIN. SESSION scope typically needs no special privilege.

How does Galaxy help avoid this error?

Galaxy highlights read-only variables in autocomplete and warns before execution, letting engineers catch the issue inside the editor.

Start Querying with the Modern SQL Editor Today!
Welcome to the Galaxy, Guardian!
You'll be receiving a confirmation email

Follow us on twitter :)
Oops! Something went wrong while submitting the form.

Check out some other errors

Trusted by top engineers on high-velocity teams
Aryeo Logo
Assort Health
Curri
Rubie Logo
Bauhealth Logo
Truvideo Logo