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 中的请求之间持久化对象 2022-01-01
- Libpuzzle 索引数百万张图片? 2022-01-01
- 通过 PHP SoapClient 请求发送原始 XML 2021-01-01
- 在 PHP 中强制下载文件 - 在 Joomla 框架内 2022-01-01
- mysqli_insert_id 是否有可能在高流量应用程序中返回 2021-01-01
- XAMPP 服务器不加载 CSS 文件 2022-01-01
- 超薄框架REST服务两次获得输出 2022-01-01
- 在 Woocommerce 中根据运输方式和付款方式添加费用 2021-01-01
- WooCommerce 中选定产品类别的自定义产品价格后缀 2021-01-01
- 在多维数组中查找最大值 2021-01-01