How to update a table automatically as another table is updated on different mysql server?(如何在不同的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服务器上更新另一个表时自动更新一个表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何在不同的mysql服务器上更新另一个表时自动更新一个表?
基础教程推荐
- PHP 类:全局变量作为类中的属性 2021-01-01
- 有什么方法可以用编码 UTF-8 而不是 Unicode 返回 PHP`json_encode`? 2021-01-01
- Cron Jobs 调用带有变量的 PHP 脚本 2022-01-01
- YouTube API v3 点赞视频,但计数器不增加 2022-01-01
- 在PHP中根据W3C规范Unicode 2022-01-01
- 如何在 Laravel 5.3 注册中添加动态下拉列表列? 2021-01-01
- 如何在 Laravel 中使用 React Router? 2022-01-01
- 学说 dbal querybuilder 作为准备好的语句 2022-01-01
- PHP PDO MySQL 查询 LIKE ->多个关键词 2021-01-01
- 如何替换eregi() 2022-01-01
