DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Please enter at least three characters to search
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Zones

Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

Last call! Secure your stack and shape the future! Help dev teams across the globe navigate their software supply chain security challenges.

Modernize your data layer. Learn how to design cloud-native database architectures to meet the evolving demands of AI and GenAI workloads.

Releasing software shouldn't be stressful or risky. Learn how to leverage progressive delivery techniques to ensure safer deployments.

Avoid machine learning mistakes and boost model performance! Discover key ML patterns, anti-patterns, data strategies, and more.

Related

  • Why Database Migrations Take Months and How to Speed Them Up
  • Unmasking Entity-Based Data Masking: Best Practices 2025
  • How Trustworthy Is Big Data?
  • Fixing Common Oracle Database Problems

Trending

  • Ensuring Configuration Consistency Across Global Data Centers
  • Grafana Loki Fundamentals and Architecture
  • Java's Quiet Revolution: Thriving in the Serverless Kubernetes Era
  • How To Develop a Truly Performant Mobile Application in 2025: A Case for Android
  1. DZone
  2. Data Engineering
  3. Databases
  4. Using the super_read_only System Variable

Using the super_read_only System Variable

This blog post will discuss how to use the MySQL super_read_only system variable to prevent people from making unauthorized DML queries on your slave servers.

By 
Pablo Padua user avatar
Pablo Padua
·
Oct. 03, 16 · Tutorial
Likes (1)
Comment
Save
Tweet
Share
10.5K Views

Join the DZone community and get the full member experience.

Join For Free

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:

mysql> SET GLOBAL read_only = 1;
Query OK, 0 rows affected (0.00 sec)


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:

mysql> SELECT @@global.read_only, @@global.super_read_only;
+--------------------+--------------------------+
| @@global.read_only | @@global.super_read_only |
+--------------------+--------------------------+
|                  1 |                        0 |
+--------------------+--------------------------+
1 row in set (0.01 sec)
mysql> SHOW GRANTSG
*************************** 1. row ***************************
Grants for nosuper@localhost: GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, RELOAD, SHUTDOWN, PROCESS, FILE, REFERENCES, INDEX, ALTER, SHOW DATABASES, CREATE TEMPORARY TABLES, LOCK TABLES, EXECUTE, REPLICATION SLAVE, REPLICATION CLIENT, CREATE VIEW, SHOW VIEW, CREATE ROUTINE, ALTER ROUTINE, CREATE USER, EVENT, TRIGGER, CREATE TABLESPACE ON *.* TO 'nosuper'@'localhost' IDENTIFIED BY PASSWORD <secret>
1 row in set (0.00 sec)
mysql> INSERT INTO test.example VALUES (1);
ERROR 1290 (HY000): The MySQL server is running with the --read-only option so it cannot execute this statement


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

mysql> SELECT @@global.read_only, @@global.super_read_only;
+--------------------+--------------------------+
| @@global.read_only | @@global.super_read_only |
+--------------------+--------------------------+
|                  1 |                        0 |
+--------------------+--------------------------+
1 row in set (0.01 sec)
mysql> SHOW GRANTSG
*************************** 1. row ***************************
Grants for super@localhost: GRANT ALL PRIVILEGES ON *.* TO 'super'@'localhost' IDENTIFIED BY PASSWORD '*3E26301B12AE2B8906D9F09785359751700930E8'
1 row in set (0.00 sec)
mysql> INSERT INTO test.example VALUES (1);
Query OK, 1 row affected (0.01 sec)


Now we will enable super_read_only and try to INSERT data again with both users:
mysql> SET GLOBAL super_read_only = 1;
Query OK, 0 rows affected (0.00 sec)
mysql> SELECT @@global.read_only, @@global.super_read_only;
+--------------------+--------------------------+
| @@global.read_only | @@global.super_read_only |
+--------------------+--------------------------+
|                  1 |                        1 |
+--------------------+--------------------------+
1 row in set (0.00 sec)
mysql> SHOW GRANTSG
*************************** 1. row ***************************
Grants for super@localhost: GRANT ALL PRIVILEGES ON *.* TO 'super'@'localhost' IDENTIFIED BY PASSWORD '*3E26301B12AE2B8906D9F09785359751700930E8'
1 row in set (0.00 sec)
mysql> INSERT INTO test.example VALUES (1);
ERROR 1290 (HY000): The MySQL server is running with the --read-only (super) option so it cannot execute this statement


mysql> SELECT @@global.read_only, @@global.super_read_only;
+--------------------+--------------------------+
| @@global.read_only | @@global.super_read_only |
+--------------------+--------------------------+
|                  1 |                        1 |
+--------------------+--------------------------+
1 row in set (0.00 sec)
mysql> SHOW GRANTSG
*************************** 1. row ***************************
Grants for nosuper@localhost: GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, RELOAD, SHUTDOWN, PROCESS, FILE, REFERENCES, INDEX, ALTER, SHOW DATABASES, CREATE TEMPORARY TABLES, LOCK TABLES, EXECUTE, REPLICATION SLAVE, REPLICATION CLIENT, CREATE VIEW, SHOW VIEW, CREATE ROUTINE, ALTER ROUTINE, CREATE USER, EVENT, TRIGGER, CREATE TABLESPACE ON *.* TO 'nosuper'@'localhost' IDENTIFIED BY PASSWORD <secret>
1 row in set (0.00 sec)
mysql> INSERT INTO test.example VALUES (1);
ERROR 1290 (HY000): The MySQL server is running with the --read-only (super) option so it cannot execute this statement


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:

  • set –read_only on when –super_read_only is used as a command line optionhttps://bugs.launchpad.net/percona-server/+bug/1389935Fixed on Percona Server 5.6.26-74.0
  • MySQL aborts when you enable super_read_only with read_onlyhttps://bugs.launchpad.net/percona-xtradb-cluster/+bug/1483956Fixed on Percona Server 5.6.26-74.0
  • super_read_only mode breaks replication with some querieshttps://bugs.launchpad.net/percona-server/+bug/1441259Fixed on Percona Server 5.6.28-76.1

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

  • https://www.percona.com/doc/percona-server/5.6/management/super_read_only.html
  • https://dev.mysql.com/doc/refman/5.7/en/server-system-variables.html#sysvar_super_read_only
Database

Published at DZone with permission of Pablo Padua, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

Related

  • Why Database Migrations Take Months and How to Speed Them Up
  • Unmasking Entity-Based Data Masking: Best Practices 2025
  • How Trustworthy Is Big Data?
  • Fixing Common Oracle Database Problems

Partner Resources

×

Comments
Oops! Something Went Wrong

The likes didn't load as expected. Please refresh the page and try again.

ABOUT US

  • About DZone
  • Support and feedback
  • Community research
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends:

Likes
There are no likes...yet! 👀
Be the first to like this post!
It looks like you're not logged in.
Sign in to see who liked this post!