简体   繁体   English

PHP / MySQL概念数据库'同步'问题

[英]PHP / MySQL Conceptual Database 'Sync' question

I am working on a PHP class implementing PDO to sync a local database's table with a remote one. 我正在开发一个实现PDO的PHP类,以将本地数据库的表与远程数据库同步。

The Question 问题

I am looking for some ideas / methods / suggestions on how to implement a 'backup' feature to my 'syncing' process. 我正在寻找关于如何在“同步”过程中实现“备份”功能的一些想法/方法/建议。 The ideas is : Before the actual insert of the data takes place, I do a full wipe of the local table's data. The ideas is :在实际插入数据之前,我会完全擦除本地表的数据。 Time is not a factor so I figure this is the cleanest and simplest solution and I wont have to worry about checking for differences in the data and all that jazz. 时间不是一个因素所以我认为这是最干净,最简单的解决方案,我不必担心检查数据和所有爵士乐的差异。 The Problem is , I want to implement some kind of security measure in case there is a problem during the insert of data, like loss of internet connection or something. The Problem is ,我希望在数据插入过程中出现问题时实施某种安全措施,例如丢失互联网连接等。 The only idea I have so far is: Copy said table to be synced -> wipe said table -> insert remote tables data into local table -> if successful delete backup copy. 到目前为止我唯一的想法是:复制表示要同步 - >擦除表 - >将远程表数据插入本地表 - >如果成功删除备份副本。

Check out mk-table-sync . 查看mk-table-sync It compares two tables on different servers, using checksums of chunks of rows. 它使用行块的校验和来比较不同服务器上的两个表。 If a given chunk is identical between the two servers, no copying is needed. 如果两个服务器之间的给定块相同,则不需要复制。 If the chunk differs, it copies just the chunk it needs. 如果块不同,它只复制它所需的块。 You don't have to wipe the local table. 您不必擦除本地表。

Another alternative is to copy the remote data to a distinct table name. 另一种方法是将远程数据复制到不同的表名。 If it completes successfully, then DROP the old table and RENAME the new local copy to the original table's name. 如果成功完成,则DROP旧表并将新的本地副本重命名为原始表的名称。 If the copy fails or is interrupted, then drop the local copy with the distinct name and try again. 如果复制失败或被中断,则删除具有不同名称的本地副本,然后重试。 Meanwhile, your other local table with the previous data is untouched. 同时,您的其他本地表与之前的数据保持不变。

Following is Web tool that sync database between you and server or other developer. 以下是在您与服务器或其他开发人员之间同步数据库的Web工具。

It is Git Based. 这是基于Git。 So you should use Git in project. 所以你应该在项目中使用Git。

But it only helpful while developing Application. 但它只在开发应用程序时有用。 it is not tool for compare databases. 它不是比较数据库的工具。

For Sync Databases you regularly push code to Git. 对于同步数据库,您经常将代码推送到Git。

Git Project : https://github.com/hardeepvicky/DB-Sync Git项目: https//github.com/hardeepvicky/DB-Sync

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM