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 HFSS 中的 H 场图与 MATLAB 中绘制的 B1 场 部分对应不上
  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?