同步2个MySQL数据库
我有 2 个 MySql 数据库,我想让它们保持同步。问题是我无权访问运行“master”数据库的机器,我只有读取权限。
所以我创建了一个辅助数据库,我想创建一个 cron 作业来每天 12:00(例如)与主数据库同步。
最好的方法是什么?
I have 2 MySql databases and I want keep them in sync. The problem is that I dont have access to the machine that runs the "master" database, I only have rights to read.
So I created a secondary database and I want to create a cron job to sync with the master one every day at 12:00 (for example).
What is the best way to do this ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
使用 MySQL Maatkit 工具包中的 mk-table-sync。
从文档中可以看出:
除了能够自动使表同步之外,它还有一个 --dry-run 参数,该参数将仅输出手动执行此操作所需的 SQL 语句。这非常有助于说服自己为 mk-table-sync 选择了正确的命令行参数,并且当您真正同步表时它将正常工作。
Use mk-table-sync from the Maatkit toolkit for MySQL.
From the documentation:
In addition to being able to automatically bring the tables into sync, it has a --dry-run argument that will just output the SQL statements necessary to manually do it. That's great for convincing yourself that you chose the correct command line arguments for mk-table-sync and that it will work properly when you have it really sync the tables.
最简单但可能开销最大的方法就是简单地执行 mysql 转储并将数据重新导入到第二个数据库中。
The most simple, but possibly the one with the most overhead, would be simply do a mysql-dump and re-import the data into the second database.
我的解决方案是创建一个 python 脚本来重新导入所有数据。无论如何,我需要更改 django-app 的表名称。
My solution was to create a python script to re-import all the data. I needed to change the table names anyway for the django-app.