问题描述
我们正在各个商店中运行带有MySql后端的Java PoS(销售点)应用程序.我想使商店中的数据库与主机服务器上的数据库保持同步.
We are running a Java PoS (Point of Sale) application at various shops, with a MySql backend. I want to keep the databases in the shops synchronised with a database on a host server.
在商店中进行某些更改时,应在主机服务器上对其进行更新.我该如何实现?
When some changes happen in a shop, they should get updated on the host server. How do I achieve this?
推荐答案
创建复制不是很困难.
这里有一些很好的教程:
Here's some good tutorials:
http://aciddrop.com/2008/01/10/step-by-step-how-to-setup-mysql-database-replication/
http://www.ghacks.net /2009/04/09/set-up-mysql-database-replication/
http://dev.mysql.com/doc/refman/5.5/en/replication-howto.html
http://www.lassosoft.com/Beginners-Guide-to -MySQL复制
这里您需要牢记一些简单的规则(当然还有更多,但这是主要概念):
Here some simple rules you will have to keep in mind (there's more of course but that is the main concept):
- 设置1个服务器(主服务器)以写入数据.
- 设置1个或多个服务器(从属服务器)以读取数据.
这样,您将避免错误.
This way, you will avoid errors.
例如:如果您的脚本插入到主服务器和从服务器上的相同表中,则将存在重复的主键冲突.
For example:If your script insert into the same tables on both master and slave, you will have duplicate primary key conflict.
您可以将从属"视为备份"服务器,该服务器具有与主服务器相同的信息,但是不能直接添加数据,只能遵循主服务器的指示.
You can view the "slave" as a "backup" server which hold the same information as the master but cannot add data directly, only follow what the master server instructions.
注意:当然,您可以从主服务器读取数据,也可以写入从服务器,但请确保不要写入同一表(主服务器到从服务器以及从服务器到主服务器).
我建议监视您的服务器,以确保一切正常.
I would recommend to monitor your servers to make sure everything is fine.
让我知道您是否需要其他帮助
Let me know if you need additional help
这篇关于MySQL数据库在两个数据库之间同步的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!