In a Master/Slave replication data consistency is a biggest concern and is very easy to break your replication with issues such as duplicate keys, missing rows , accidental writes from application connected to the slave or even by a DBA connected to the slave 🙁 “yes things happen” .
1. read_only
When the read_only system variable is enabled, the server permits no client updates except from users who have theSUPER privilege. This variable is disabled by default.
It’s a good practice then to set read_only=1
on slave servers to prevent any (accidental) writes.
Unfortunately users with the SUPER privilege can override the setting and could still run DML queries.
2. super_read_only
However, since Percona Server 5.6.21 and MySQL 5.7.8, you can use the super_read_only feature to extend the read_only option and apply it to users with SUPER privileges. If the super_read_only=1
the server prohibits client updates even from users who have SUPER
.
3. temporary use of slave-skip-errors
With slave-skip-errors you can make the replication slave ignore certain error codes (you can find the list of MySQL error codes here: Server Error Codes and Messages)
Example : the purpose of the example below is to temporary skip error
- 1062 : Duplicate entry ‘%s’ for key %d
- 1054 : Unknown column ‘%s’ in ‘%s’
1 2 | [mysqld] slave-skip-errors=1062,1054 |
Caution : Do not use this option unless you fully understand why you are getting errors. If there are no bugs in your replication setup and client programs, and no bugs in MySQL itself, an error that stops replication should never occur. Indiscriminate use of this option results in slaves becoming hopelessly out of sync with the master, with you having no idea why this has occurred.
Here are a couple bugs to consider on Percona Server 5.6:
- set –read_only on when –super_read_only is used as a command line option
https://bugs.launchpad.net/percona-server/+bug/1389935
Fixed on Percona Server 5.6.26-74.0 - MySQL aborts when you enable super_read_only with read_only
https://bugs.launchpad.net/percona-xtradb-cluster/+bug/1483956
Fixed on Percona Server 5.6.26-74.0 - super_read_only mode breaks replication with some queries
https://bugs.launchpad.net/percona-server/+bug/1441259
Fixed on Percona Server 5.6.28-76.1
For more information, please check following 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