php连接到mysql复制
我已经为我的主服务器设置了一个从服务器,我想知道我是否需要通过 php 连接到两台服务器,或者负载平衡是否只是连接到主服务器?
//slave
$c2 = mysql_connect("10.100.27.10","<user>","<pass>")or die(mysql_error());
//master
$c =mysql_connect("10.100.27.99","<user>","<pass>")or die(mysql_error());
mysql_select_db("piksearch", $c2);
mysql_select_db("piksearch");
I have set up a slave server for my master and i want to know if i need to connect to both servers via php or is the load balanced just connecting to the master?
//slave
$c2 = mysql_connect("10.100.27.10","<user>","<pass>")or die(mysql_error());
//master
$c =mysql_connect("10.100.27.99","<user>","<pass>")or die(mysql_error());
mysql_select_db("piksearch", $c2);
mysql_select_db("piksearch");
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您只需要在母版上进行插入即可。否则,设置多主复制,然后您可以对任一数据库执行任何操作。
但要小心,特定会话始终使用相同的数据库服务器。否则,如果复制中断或备份,数据可能会不一致。
You just need to do your INSERTs on a master. Otherwise, set up multi-master replication and then you can do whatever to either database.
Be cautious though that a particular session always uses the same DB server. Otherwise, you may have inconsistent data if replication breaks, or is backed up.