如何更新表自动作为另一个表在不同的mysql服务器上更新? [英] How to update a table automatically as another table is updated on different mysql server?

查看:377
本文介绍了如何更新表自动作为另一个表在不同的mysql服务器上更新?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我有两个数据库'db1'& 'db2'在不同的mysql服务器'A'& 'db1','db2'中的'table1','db2'中的'table1' 将自动更新。



如何使用触发器或cron作业执行此操作?

解决方案

您可以使用cron作业,只需每分钟运行一次php文件。



此文件可以在db2中检查table1中的新行(保存文本文件中的当前行数以进行比较,如果新计数>旧计数,这可以更新db1中的table1。



easy



但是mysql复制@Charles在注释中说更好。


Let's say I have two databases 'db1' & 'db2' on different mysql servers 'A' & 'B' respectively.

I want to check every 6 hours if there is any update found in 'table1' in 'db2', then the 'table1' in 'db1' will be automatically updated.

How can I do that with trigger or a cron job? and when it will be fired?

解决方案

You could do with with a cron job, simply could run a php file every minute.

this file can check for a new row in a table1 in db2 (saving current count of rows in a text file for comparison, and if new count > old count, then this can then update table1 in db1.

easy

but mysql replication as @Charles said in the comment would be better.

这篇关于如何更新表自动作为另一个表在不同的mysql服务器上更新?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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