两个数据库之间的Mysql数据库同步

2021-11-20 00:00:00 database mysql

我们正在各个商店运行 Java PoS(销售点)应用程序,并使用 MySql 后端.我想让商店中的数据库与主机服务器上的数据库保持同步.

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://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 个服务器(主)用于写入数据.
  2. 设置 1 个或多个服务器(从属)用于读取数据.

这样可以避免错误.

例如:如果你的脚本插入到master和slave的同一张表中,你就会有重复的主键冲突.

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

相关文章