MySQL - 保持数据库与多个客户端同步的最佳方法

发布于 2024-11-18 00:03:04 字数 1000 浏览 5 评论 0原文

有数百个客户将使用 Windows 系统来管理自己的信息。该信息被发送到服务器进行分析(网络系统)。

客户端和服务器都将具有相同的数据库结构。有些表将通过 Windows 客户端更新,而其他表将通过 Web 系统更新。很少有表可以在两者中更新。

问题在于我们需要保持这些数据库的同步。 当前的方法是将所有“INSERT、UPDATE、DELETE”语句存储在表中,并每天更新一次客户端(打开时)和服务器(关闭时)。

我不喜欢当前的方法,因为我认为它不是很安全(即使我们对数据使用强加密),而且我相信有更好的方法来做到这一点。

我刚刚迁移到使用 MariaDB,并且正在阅读有关 Aria 存储引擎的文章:

Aria 可以重播几乎所有内容 日志。 (包括 创建/删除/重命名/截断表)。 因此,您需要备份 Aria 只需复制日志即可。

问题:

  • 您认为可以使用 Aria Logging 来解决我的问题吗(这与当前的方法有何不同)?

  • 有人有类似案例(多客户端同步)的经验吗?

  • 我只有 MyISAM 和 InnoDB 的经验...还有其他存储引擎可以更好地适合这种情况吗?

### 更新(7 月 2 日)###

我探索了使用 MySQL binlog 及其自动复制的可能性。恕我直言,该方法非常适合服务器数据与客户端中的数据完全相同的情况。 BLACKHOLE存储引擎可用于仅同步确定的表(这可能非常有用)。就我而言,服务器和客户端具有相同的结构,但它们没有相同的数据。换句话说,服务器包含所有客户端的数据,每个客户端都有自己的一组数据(保持相同的结构)。

尝试应用MySQL的自动复制,将需要在服务器中为每个客户端拥有一个数据库,这使得它更加复杂。

我想我会坚持原来的计划,因为它使我能够灵活地轻松查询每个客户的更改(直到我找到更好的方法来做到这一点)。

There are hundreds of clients that will use a windows system in which they manage their own information. That information is sent to a server for analysis (web system).

Both, the clients and the server will have the same database structure. There are some tables that will be updated through the windows clients and other tables through the web system. Few of the tables can be updated in both.

The problem reside that we need to keep synchronized those databases.
The current approach is to store in a table all the "INSERT,UPDATE,DELETE" statements and once a day update the clients (on open) and the server (on close).

I don't like the current approach as I think it is not very secure (even we are using strong encryption on the data), and I believe there is a better way to do it.

I just migrated to use MariaDB and I was reading this about the Aria Storage Engine:

Aria can replay almost everything from
the log. (Including
create/drop/rename/truncate tables).
Therefore, you make a backup of Aria
by just copying the log.

Questions:

  • Do you think it is possible to use Aria Logging to solve my problem (how does that is different of the current approach)?

  • Does anyone has any experience with a similar case (multi-client synchronization)?

  • I just have experience with MyISAM and InnoDB... is there any other Storage Engine that could be better for this case?

### UPDATE (Jul 2nd)###

I explored the possibility to use MySQL binlogs and its automatic replication. IMHO, that method is ideal for those cases in which the server data is exactly the same as in the clients. BLACKHOLE storage engine can be used to synchronize only determined tables (which may be very useful). In my case, the server and the clients have the same structure BUT they don't have the same data. In other words, the server contains all client's data, and each client has their own set of data (keeping the same structure).

Trying to apply MySQL's automatic replication, will require to have in the server a database per client, which makes it more complicated.

I think I will stick to the original plan as it gives me the flexibility to easily query the changes per client (until I found a nicer way to do it).

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文