dsh8009271 2015-10-11 09:02
浏览 71

想从命令行创建cron作业

i have built a CMS website that replies upon the mysql records of a 3rd party. i intend to download the 3rd party records via CSV. i then want to use a Cron job via my command line to update my mysql records

i know how to manually upload to mysql via CSV i.e:

LOAD DATA INFILE 'c:/tmp/discounts_2.csv'INTO TABLE discountsFIELDS TERMINATED BY ',' ENCLOSED BY '"'LINES TERMINATED BY '
'IGNORE 1 ROWS(title,@expired_date,amount)SET expired_date = STR_TO_DATE(@expired_date, '%m/%d/%Y');

however, i am not sure how to go about creating a cron job that will automtically link to the command line and then perform this function.

i guess that what i want is a pointer on how i can go about doing this.

UPDATE @fancyPants asked the question "what do i want the cronJob to do?" the answer is this. i want the cronJob job to access the CSV file (that i have previously downloaded) and then upload all those values from the CSV file to the mysql database

i know the command for doing the CSV conversion to mysql;

LOAD DATA INFILE 'c:/tmp/discounts_2.csv'INTO TABLE discountsFIELDS TERMINATED BY ',' ENCLOSED BY '"'LINES TERMINATED BY ' 'IGNORE 1 ROWS(title,@expired_date,amount)SET expired_date = STR_TO_DATE(@expired_date, '%m/%d/%Y');

i am however stuck at the point of how to do a cron job to my command line and then how to execute the above command once the cron arrives at the command line

  • 写回答

1条回答 默认 最新

  • doq91130 2015-10-11 09:59
    关注

    Create a MySQL event rather than a cronjob.

    Enable the event scheduler with

    SET GLOBAL event_scheduler = ON;
    

    and create an event like this:

    DELIMITER $
    CREATE EVENT 
    ON SCHEDULE EVERY 1 DAY
    STARTS '2015-10-11 00:00:00'
    DO
    BEGIN
    TRUNCATE TABLE discounts;
    LOAD DATA INFILE 'c:/tmp/discounts_2.csv'INTO TABLE discounts FIELDS TERMINATED BY ',' ENCLOSED BY '"'LINES TERMINATED BY '
    'IGNORE 1 ROWS(title,@expired_date,amount)SET expired_date = STR_TO_DATE(@expired_date, '%m/%d/%Y');
    END $
    DELIMITER ;
    

    and that's it.

    Read more about the syntax here and here is more general information about it.

    评论

报告相同问题?

悬赏问题

  • ¥15 Mac系统vs code使用phpstudy如何配置debug来调试php
  • ¥15 目前主流的音乐软件,像网易云音乐,QQ音乐他们的前端和后台部分是用的什么技术实现的?求解!
  • ¥60 pb数据库修改与连接
  • ¥15 spss统计中二分类变量和有序变量的相关性分析可以用kendall相关分析吗?
  • ¥15 拟通过pc下指令到安卓系统,如果追求响应速度,尽可能无延迟,是不是用安卓模拟器会优于实体的安卓手机?如果是,可以快多少毫秒?
  • ¥20 神经网络Sequential name=sequential, built=False
  • ¥16 Qphython 用xlrd读取excel报错
  • ¥15 单片机学习顺序问题!!
  • ¥15 ikuai客户端多拨vpn,重启总是有个别重拨不上
  • ¥20 关于#anlogic#sdram#的问题,如何解决?(关键词-performance)