0
DROP EVENT `deleteTestEntries`;
CREATE DEFINER=`root`@`localhost` EVENT `deleteTestEntries`
    ON SCHEDULE EVERY 1 MINUTE
    STARTS '2018-05-25 18:17:01'
    ON COMPLETION NOT PRESERVE ENABLE DO
    DELETE FROM lead_master WHERE lead_master.lname LIKE '%Test%'

What is wrong in above event. It has been created with no errors but not performing any action. I simply want to delete the records from my lead_master table where lname is 'Test'

Gordon Linoff
  • 1,242,037
  • 58
  • 646
  • 786
  • 1
    This is probably the wrong way to solve your problem. I would suggest that you ask another question with more details about your table and what you want to accomplish. – Gordon Linoff May 25 '18 at 13:08

3 Answers3

1

Go into my.ini file and add this line,most probably this is the issue.

event_scheduler = on

Restart mysql.Apparently you can even set it on the fly

Mihai
  • 26,325
  • 7
  • 66
  • 81
1

I finally did it with cron jobs. I created a controller which calls a model function contains query to delete record. and set the cron job which calls the controller after specific interval of time.

0

I am guessing that you don't need an event every minute. Just define a view to filter out the records you don't want:

create view v_lead_master as
    select lm.*
    from lead_master lm
    where lm.lname not like '%Test%';

Then schedule a job or event every day at a slow period to delete the rows you want. Your application should use the view. Your testing should use the base table.

Gordon Linoff
  • 1,242,037
  • 58
  • 646
  • 786