Prevent non-replication writes to MySQL slave?
read-only option in my.cnf. It can also be specified as a flag on the command line using
--read-only with mysqld.
As an alternative to setting
read_only=1 (e.g. when there are other scratchpad/reporting/development databases on the slave instance), I sometimes strip all privileges other than SELECT from all users to the DB that I am replicating.
That is, after running the GRANT command on the master, I run the REVOKE command on the slave.
As of MySQL 5.7.8, there is now a
super_read_only option, which prevents even SUPER users from performing client updates. It does not disrupt the replication process. As with other settings, it can be set:
- in command line format (
- as a variable in my.cnf (
- from the client prompt (
SET GLOBAL super_read_only = 1;).
super_read_onlywill prevent operations on temporary tables.
- They will not prevent metadata operations like ANALYZE TABLE and OPTIMIZE TABLE.
- Bugs for certain queries with
super_read_onlyenabled have been reported.