在 MySQL 中同步两个数据库模式 [英] Synchronize two databases schema in MySQL

查看:29
本文介绍了在 MySQL 中同步两个数据库模式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在寻找可以同步两个 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.

更多信息:

为什么复制不起作用.

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

如果是 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 ?

这篇关于在 MySQL 中同步两个数据库模式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆