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

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

问题描述

假设我有两个数据库 'db1' &'db2' 在不同的 mysql 服务器 'A' &分别是B".

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

我想每 6 小时检查 'db2' 中的 'table1' 是否有更新,然后 'db1' 中的 'table1' 会自动更新.

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.

如何使用触发器或 cron 作业来做到这一点?什么时候会被解雇?

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

推荐答案

你可以使用 cron 作业,只需每分钟运行一个 php 文件.

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

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

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.

简单

但是@Charles 在评论中说的mysql复制会更好.

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

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

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