How to code PHP MySQL class for master and slave setup?

前端 未结 4 668
抹茶落季
抹茶落季 2020-12-11 12:38

I have never used a master/slave setup for my mysql databases so please forgive if I make no sense here.

I am curious, let\'s say I want to have a master DB and 3

4条回答
  •  独厮守ぢ
    2020-12-11 13:20

    you sound like you are wanting to improve performance/balance load

    yes you need to do any destructive changes to the master database. the slaves can only be used for readonly. you would also need to be careful that you don't write to the master and read from the slave instantaneously, otherwise the data may not have been replicated to the slave yet. so any instantaneous reads would still need to come from the master.

    i wouldn't suggest just randomly selecting a slave. you could do this by geographical region if they are spread out, or if you are running in a cluster you can use a proxy to do the load balancing for you..

    here is some more info that may help

    http://agiletesting.blogspot.com/2009/04/mysql-load-balancing-and-read-write.html

提交回复
热议问题