简体   繁体   English

每10分钟从CSV文件更新一次MySQL

[英]Update MySQL from CSV file Every 10 Minutes

I am relatively new to MySQL and am looking for a way to run a MySQL update every 10 minutes. 我是MySQL的新手,正在寻找一种每10分钟运行一次MySQL更新的方法。 Basically there is a central CSV file that is updated every ten minutes on a server that we grab the data from. 基本上,有一个中央CSV文件,该文件每十分钟在我们从中获取数据的服务器上更新一次。 I am trying to set up a MySQL table that will read that CSV file and load it into the MySQL table every ten minutes. 我正在尝试设置一个MySQL表,该表将读取该CSV文件,并每隔十分钟将其加载到MySQL表中。

I know that you can link a MySQL table to a CSV file directly using 'load data.' 我知道您可以使用“加载数据”直接将MySQL表链接到CSV文件。 My confusion comes with the actual automatic updating. 我的困惑来自实际的自动更新。 I've done some research and read about 'cron' jobs which will perform automated tasks at set intervals. 我进行了一些研究,并阅读了有关“ cron”作业的信息,这些作业将按设定的时间间隔执行自动化任务。 My thought is to have the PHP script run by the cron job every ten minutes (if the host allows it). 我的想法是让cron作业每十分钟运行一次PHP脚本(如果主机允许的话)。

I'm just wondering if this is best practice. 我只是想知道这是否是最佳做法。 I've been searching around and don't see many other options and wanted to see if you all knew of any other methods that I may be missing so I can make a proper assessment of this job. 我一直在搜寻,没有看到许多其他选择,并且想看看你们是否都知道我可能会缺少的任何其他方法,因此我可以对这项工作进行适当的评估。 Thanks for your help! 谢谢你的帮助!

cron is going to be the way to go. cron将成为必经之路。 Depending on the size of the file loaded it might be an expensive task (in terms of time). 根据所加载文件的大小,这可能是一项昂贵的任务(就时间而言)。 I would suggest having the cron upload the file to a temp table then within a transaction drop the old table then rename the temp table to the correct table name. 我建议cron将文件上传到临时表,然后在事务中删除旧表,然后将临时表重命名为正确的表名。 If the file is relatively small then it might make sense to walk each line in the file and determine if based on querying the database a record needs to be added or updated. 如果文件相对较小,则遍历文件中的每一行并基于查询数据库确定是否需要添加或更新记录可能很有意义。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM