在 MySQL 中同步两个数据库模式两个、模式、数据库、MySQL

2023-09-08 09:42:33 作者:其实牢记

我一直在寻找可以同步两个 MySQL 数据库模式的可移植脚本或命令行程序.我不是在寻找基于 GUI 的解决方案,因为它无法自动化或使用构建/部署工具运行.

I was looking for a portable script or command line program that can synchronize two MySQL databases schema. I am not looking for a GUI based solution because that can't be automated or run with the buid/deployment tool.

基本上它应该做的是扫描database1和database2.检查架构差异(表和索引)并提出一堆 SQL 语句在其中一个上运行,以使其获得与另一个相似的结构,尽可能减少数据损坏.

Basically what it should do is scan database1 and database2. Check the schema difference (tables and indexes) and propose a bunch of SQL statements to run on one so that it gets the similiar structure of the other minimizing data damage as much as possible.

如果有人可以指出实现此类解决方案的 PHP、Python 或 Ruby 包,我可以尝试从那里复制代码.

If someone can indicate a PHP, Python or Ruby package where this type of solution is implemented, I can try to copy the code from there.

很多 MySQL GUI 工具可能都可以做到这一点,但我正在寻找可编写脚本的解决方案.

A lot of MySQL GUI tools probably can do this, but I am looking for a scriptable solution.

抱歉没有更清楚:我正在寻找的是表结构中的同步,同时尽可能保持数据完整.不是数据复制.

Sorry for not being more clear: What I am looking for is synchronization in table structure while keeping data intact as far as possible. Not data replication.

更多信息:

为什么复制不起作用.

安装基地遍布全州.我们希望安装程序根据最新版本中的 chagnes 对数据库执行动态修复,而不管最终用户可能使用的是哪个旧版本.更改大多类似于向表添加新列、创建新索引或删除索引、添加表或删除系统内部使用的表(我们不删除用户数据表).

如果是 GUI:不,不能使用.我们不想仅仅为了 DB diff 将 20MB 的应用程序与我们的安装程序捆绑在一起.特别是当原始安装程序小于 1 MB 时.

If it's a GUI: No it can't be used. We don't want to bunddle a 20MB app with our installer just for DB diff. Specially when the original installer is less than 1 MB.

推荐答案

你有没有考虑过使用 MySQL 复制 ?

Have you considered using MySQL replication ?