douweng3564 2013-05-12 06:45
浏览 96
已采纳

每隔10分钟从CSV文件更新MySQL

I am relatively new to MySQL and am looking for a way to run a MySQL update every 10 minutes. Basically there is a central CSV file that is updated every ten minutes on a server that we grab the data from. 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.

I know that you can link a MySQL table to a CSV file directly using 'load data.' 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. My thought is to have the PHP script run by the cron job every ten minutes (if the host allows it).

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!

  • 写回答

1条回答 默认 最新

  • douhuang4166 2013-05-12 06:52
    关注

    cron is going to be the way to go. 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. 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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度