更新两个mysql查询之间的差异
我正在开发一个web应用程序,它使用来自我拥有只读权限的远程数据库的一些数据。该数据库中的数据SATMANAGE每5分钟更新一次。对于我的应用程序,我需要远程数据库表IDIRECT_STATUS中的一些列 自动取款机。我有一个cron作业,从CLI执行查询并将数据存储在.txt文件中。然后它截断本地表,并使用LOAD DATA local INFILE重新填充更新的数据 到目前为止,这一切进展顺利。随着应用程序变得越来越复杂,我需要一种改变本地“remotes”表的方法。而我现在截断本地“remotes”表。我只需要使用远程“IDIRECT_STATUS”表中的更新数据更新表。这使我能够在本地“remotes”表中包含远程“IDIRECT_STATUS”表中不存在的列 这就是我要找的。左边是遥控桌。我想在相应的列中保留右侧的本地数据库和左侧的远程数据库。这不会截断本地表,从而使附加的本地列保持其状态更新两个mysql查询之间的差异,mysql,cron,sync,Mysql,Cron,Sync,我正在开发一个web应用程序,它使用来自我拥有只读权限的远程数据库的一些数据。该数据库中的数据SATMANAGE每5分钟更新一次。对于我的应用程序,我需要远程数据库表IDIRECT_STATUS中的一些列 自动取款机。我有一个cron作业,从CLI执行查询并将数据存储在.txt文件中。然后它截断本地表,并使用LOAD DATA local INFILE重新填充更新的数据 到目前为止,这一切进展顺利。随着应用程序变得越来越复杂,我需要一种改变本地“remotes”表的方法。而我现在截断本地“rem
IDIRECT_STATUS remotes
-------------------------------|-------------------------------
id | id
netmodem_name | netmodem_name
nms_name | nms_name
ip_addr | ip_addr
serial_no | serial_no
last_date_online | last_date_online
last_updated | last_updated
network_name | network_name
network_id | network_id
is_mobile | is_mobile
latitude | latitude
longitude | longitude
lnb_name | lnb_name
buc_name | buc_name
upstream_qos_profile_name | upstream_qos_profile_name
downstream_qos_profile_name | downstream_qos_profile_name
inroute_maximum_data_rate | inroute_maximum_data_rate
outroute_maximum_data_rate | outroute_maximum_data_rate
upstream_cir | upstream_cir
use_upstream_cir | use_upstream_cir
crtp_enabled | crtp_enabled
INROUTE_GROUP_ID | INROUTE_GROUP_ID
| excluded (Not updated or deleted)
| excluded_to (Not updated or deleted)
| shipowner_id (Not updated or deleted)
| etc... (Not updated or deleted ...)
希望你们这些了不起的家伙能帮助我。我有任何不清楚的地方,请让我知道,我会尽快编辑问题 我在左表中看到一个名为
last\u updated
的字段。我建议使用一个简单的perl或php脚本进行加载,这样可以执行以下操作:
a) 单击本地表中的最新更新时间
b) 从上次插入后已更新的远程表中选择数据
c) 使用远程数据更新本地表
在php代码中,它看起来像这样:
<?
// select the last update time
$sql = "select max(last_updated) as last_update_time from remotes";
$r = mysql_query($sql);
$row = mysql_fetch_assoc($r);
// save the last upate time
$last_update_time = $row['last_update_time'];
// get newer rows from the remote database
$sql = "select * from IDIRECT_STATUS where last_updated > ".$last_update_time;
$r = mysql_query($sql);
while ($row = mysql_fetch_assoc($r)) {
// generate update queries
$sql = "update remotes set netmodem_name='".$row['netmodem_name']."', ... last_updated='".$row['last_updated']."' where id=".$row['id'];
// execute query
mysql_query($sql);
}
?>
我在左表中看到一个名为上次更新的字段。我建议使用一个简单的perl或php脚本进行加载,这样可以执行以下操作: a) 单击本地表中的最新更新时间 b) 从上次插入后已更新的远程表中选择数据 c) 使用远程数据更新本地表 在php代码中,它看起来像这样:
<?
// select the last update time
$sql = "select max(last_updated) as last_update_time from remotes";
$r = mysql_query($sql);
$row = mysql_fetch_assoc($r);
// save the last upate time
$last_update_time = $row['last_update_time'];
// get newer rows from the remote database
$sql = "select * from IDIRECT_STATUS where last_updated > ".$last_update_time;
$r = mysql_query($sql);
while ($row = mysql_fetch_assoc($r)) {
// generate update queries
$sql = "update remotes set netmodem_name='".$row['netmodem_name']."', ... last_updated='".$row['last_updated']."' where id=".$row['id'];
// execute query
mysql_query($sql);
}
?>
感谢您为我指明了正确的方向。没有想到上次更新的字段。稍后我会尝试一下,看看是否能找到一个合适的解决方案。谢谢你给我指明了正确的方向。没有想到上次更新的字段。我稍后会尝试一下,看看是否能找到一个合适的解决方案。