2

After setting up mysql replications with master/slave db scheme, I noticed that the slave db server is not read-only. Of cause, after that I configured it manually in /etc/my.cnf file.

I just can't understand: isn't it the default behavior that the slaves are always running in the read-only mode or it should be always configured by hand?

Andrey Pesoshin
  • 123
  • 1
  • 6

4 Answers4

1

No it is not the default behavior, and yes if you want slaves to be read only you need to do so "by hand" (or script).

The reason for this is mostly just because thats how it started and it hasn't been changed since. However there are plenty of ways in which this is the desired behavior, for instance if your slaves have some tables that your master does not (like reporting summary tables). Or, if you want to run an ALTER you can run it on your slave first, failover, then run it on your master so as not to impact the live site.

cagenut
  • 4,808
  • 2
  • 23
  • 27
0

I think that the read-only mode is only per user basis, not globally for the slave So make sure you are not replicating the users (database 'mysql'), and if necessary create users with only USAGE grant option - that way those users have read-only.

3molo
  • 4,340
  • 5
  • 30
  • 46
  • you know, read-only mode can be set for entire server in /etc/my.cnf. The question was about why isn't it the default behaviour because writing to slave (if it isn't in readonly mode) causes the data desync and replications become not working from this moment – Andrey Pesoshin Nov 01 '10 at 09:28
0

Although many of our slaves are set to read_only, a few of them are not.

In these instances, it is usually because we house other development/scratchpad/reporting databases on these servers. In these cases, users are only granted SELECT permissions to the primary db, but SELECT/UPDATE permissions to the secondary db's.

Moreover, if multi-master replication was being used, having the slaves be read_only by default would be a serious problem. :)

Riedsio
  • 273
  • 4
  • 7
0

It is quite common to not have the slave in read_only mode..

in fact, if you do not set it yourself, then it never is enabled..

A good question, is why you would actually want to set it...???

Are you trying to protect mistakes? or errors made my admin users??? or the application?
Considering MANY admins are using MySQL as root anyways, where is the protection here??
You cant exactly protect your data as you would imagine ( as everything replicated into the slave anyway )

You do know that any user with super privileges and the replication thread do not abide by the read_only??

A strong structured approach to users and privileges is the correct way to deal with replication issues, not a read_only configuration on the slave

In my honest opinion, it actually does not protect very much...or useful for anything besides stopping a few users not write.. ( which on production systems - should never happen anyways )

As an example, In Mysql-Multi-Master ( read_only is set by the scripts ) This in theory is only to simply decide which server is the "True Master" in the master-master configuration..

All in all.. Forget about read_only ( its really unneccesary, and probably wont protect you from what you imagine it will )

Arenstar
  • 3,592
  • 2
  • 24
  • 34
  • This answer is now outdated, mysql now supports super_read_only. And infact readonly slaves are now encouraged wherever there is some use case for this. – rahul tyagi Jan 22 '20 at 07:19