TRY AND ERROR

気になったこと、勉強したこと、その他雑記など色々メモしていきます。。Sometimes these posts will be written in English.,

mysqlのレプリケーションでスレーブがreadonlyにならない!!

久々のブログです。。

 

mysql5.7でmaster-slaveのレプリケーション設定でハマったのでメモ。

 

slaveをreadonlyにしたかったので、my.cnfに

read_only=1を追加しサービス再起動、試しにslaveに更新系のクエリを投げてみたところ、更新できちゃう!!

 

意味が分からず格闘すること数時間、以下のようなドキュメントを発見。

 

Finally, in order to make the slave instance read-only, parameter read_only is set to 1. You should be careful with this option since it doesn’t completely prevent changes on the slave. Even when the read_only is set to 1, updates will be permitted only from users who have the SUPER privilege. MySQL has recently introduced the new parameter super_read_only to prevent SUPER users making changes. This option is available with version 5.7.8.

MySQL Master-Slave Replication Tutorial | Toptal

 

 

どうやら、そもそもroot系の権限があるユーザーでは更新できる仕様らしいです。


基本的にアプリ用に CRUD権限を付与しているユーザーでDBAを使っていればread_only=1でOKだと思いますが、v5.7.8からsuper_read_only=1にすると上記ユーザーでも更新不可にできるようです。

 

slaveのmaster昇格などを考えないのなら、read_only=1に加えてsuper_read_only=1を設定しておいてもいいかもしれません。