如何编写PHP MySQL类进行主从设置? [英] How to code PHP MySQL class for master and slave setup?

查看:59
本文介绍了如何编写PHP MySQL类进行主从设置?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我从来没有为我的mysql数据库使用主/从设置,所以如果我在这里没有道理,请原谅.

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

我很好奇,假设我想拥有一个主数据库和3个从属数据库.我是否需要编写数据库类来连接条目并将其添加/更新/删除到主数据库,或者这是以某种方式自动化的?

I am curious, let's say I want to have a master DB and 3 slave DB's. Would I need to write my database classes to connect and add/update/delete entries to the master DB or is this automated somehow?

对于我的SELECT查询,我是否需要对其进行编码以随机选择随机数据库服务器?

Also for my SELECT queries, would I need to code it to randomly select a random DB server?

推荐答案

您要使用(和研究)的是

What you want to use (and research) is MySQL Replication. This is handled completely independent of your code. You work with the database the same as if there were 1 or 100 servers.

这篇关于如何编写PHP MySQL类进行主从设置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆