search

Home  >  Q&A  >  body text

php - How to regularly import data from a mysql data table to another table in the same database

Want to import all today's sign-in data table signInfo into another table yesterdaySignInfo in the same database at 23:59 every day? Can it be done using only sql statements?

PHP中文网PHP中文网2782 days ago373

reply all(2)I'll reply

  • PHP中文网

    PHP中文网2017-05-16 13:06:21

    Can be solved using mysql events

    //Open event scheduler

    set global event_scheduler = on  

    //Create event

    delimiter $$
    create event if not exists yesterday_sign_log
    on schedule every 1 day
    starts timestamp '2017-05-03 23:50'
    on completion preserve enable
    do begin
    drop table if exists yesterdaySignInfo;
    create table yesterdaySignInfo like signInfo;
    insert into yesterdaySignInfo select * from signInfo;
    end $$
    delimiter;

    reply
    0
  • PHP中文网

    PHP中文网2017-05-16 13:06:21

    SQL can be written like this

    drop table if exists yesterdaySignInfo;
    create table yesterdaySignInfo like signInfo;
    insert into yesterdaySignInfo select * from signInfo;

    reply
    0
  • Cancelreply