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服务器上更新另一个表时自动更新一个表?


- Laravel 仓库 2022-01-01
- Mod使用GET变量将子域重写为PHP 2021-01-01
- 带有通配符的 Laravel 验证器 2021-01-01
- PHP Count 布尔数组中真值的数量 2021-01-01
- Oracle 即时客户端 DYLD_LIBRARY_PATH 错误 2022-01-01
- 没有作曲家的 PSR4 自动加载 2022-01-01
- 从 PHP 中的输入表单获取日期 2022-01-01
- 正确分离 PHP 中的逻辑/样式 2021-01-01
- 如何定位 php.ini 文件 (xampp) 2022-01-01
- SoapClient 设置自定义 HTTP Header 2021-01-01