Using the MySQL super_read_only system variable

super_read_only-system-variableThis blog post will discuss how to use the MySQL super_read_only system variable.

It is well known that replica servers in a master/slave configuration, to avoid breaking replication due to duplicate keys, missing rows or other similar issues, should not receive write queries. It’s a good practice to set read_only=1 on slave servers to prevent any (accidental) writes. Servers acting as replicas will NOT be in read-only mode automatically by default.

Sadly,  read_only has a historical issue: users with the SUPER privilege can override the setting and could still run DML queries. Since Percona Server 5.6.21 and MySQL 5.7.8, however, you can use the super_read_only feature to extend the read_only  option and apply it to users with SUPER privileges.

Both  super_read_only and  read_only  are disabled by default, and using  super_read_only implies that  read_only  is automatically ON as well. We’ll demonstrate how read_only and super_read only work:

As expected, with the read_only variable enabled, users without SUPER privilege won’t be able to INSERT values, and instead, they will get an ERROR 1290 message:

However, users with SUPER privileges can INSERT values on the table:

Now we will enable super_read_only and try to INSERT data again with both users:


As you can see above, now even users with SUPER privileges can’t make updates or modify data. This is useful in replication to ensure that no updates are accepted from the clients, and are only accepted by the master.

When enabling the super_read_only system variable, please keep in mind the following implications:

  • Setting super_read_only ON implicitly forces read_only ON
  • Setting read_only OFF implicitly forces super_read_only OFF

There are some other implications for read_only that apply to  super_read_only as well:

  • Operations on temporary tables are allowed no matter how these variables are set:
    • Updates performed by slave threads are permitted if the server is a replication slave. In replication setups, it can be useful to enable super_read_only on slave servers to ensure that slaves accept updates only from the master server and not from clients.
  • OPTIMIZE TABLE and ANALYZE TABLE operations are allowed as well since the purpose of the read-only mode is to prevent changes to table structure or contents but not to table metadata like index stats.
  • You will need to manually disable it when you promote a replica server to the role of master.

There are few bugs related to this variable that might be useful to take into consideration if you’re running on Percona Server 5.6:

For more information, please refer to this following documentation links:

Share this post

Comments (2)

  • Gillian

    “OPTIMIZE TABLE” isn’t allowed with *read_only=ON, at least in my testing of MyISAM and InnoDB tables. This makes sense for InnoDB since the operation is mapped to “ALTER TABLE”, and it requires the INSERT privilege.

    September 28, 2016 at 2:44 pm
  • Gillian

    Forgot to correct and clarify my earlier comment: OPTIMIZE TABLE is allowed with read-only/super-read-only ON in 5.6 but not 5.7:

    December 29, 2016 at 6:19 pm

Comments are closed.